我如何将字符串转换成数组? [英] How do I convert a string into an array?

查看:143
本文介绍了我如何将字符串转换成数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的字符串串串=黑门,白色的门,冲门
现在我想把这个字符串转换成数组。
我采用分 myArray的= strings.split('')则数组是这样的:黑色,门,白,门,红,门。

I have a string like this string strings=" black door,white door,red door "
Now I want to put this string into array.
I use split myarray = strings.split(',') then array look like this: black,door,white,door,red,door.

我希望把串入阵逗号每个次数不上的空间后。我希望这样的数组中:  黑门,白色的门,红色的门。

I want to put the string into the array after each occurance of comma not on the space. I want it like this in the array: black door,white door,red door.

推荐答案

如果您有黑门,白色的门,冲门的字符串,然后只使用作为分隔符

if you have "black door,white door,red door" string then use only , as separator

var result = "black door,white door,red door".Split(',');

这篇关于我如何将字符串转换成数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆