将字符串的值更改为字符串数组 [英] changing values of a string to string array

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

问题描述

我碰巧有一个字符串,其格式为:''me,you,i,jane,'''',我想借助数组将其值更改为单个单词的集合例如''''me'''',''''you'''',''i'''',''jane''''

i happen to have a string thats in this format: ''''me, you, i, jane,'''' and i would like to change its values into a collection of individual words with the help of an array e.g ''''me'''', ''''you'''', ''''i'''', ''''jane''''

推荐答案

string[] arr = my.Split(new char[]{'',''});



按您希望的方式操纵数组的顺序,然后再次创建字符串.



Manipulated the order of the array any way you wish and create the string again.

myString = String.Join(",", Array);


在返回的数组的每个元素上使用string.Split,然后使用string.Trim:
Use string.Split, and then string.Trim on each element of the array that is returned:
string[] words = my.Split('','');
for(int wi = 0; wi < words.Length; wi++) wi[i] = wi[i].Trim();


如果您不关心空格,则自行拆分即可.


If you don''t care about white space, Split on its own will do the job.


string[] array = myString.Split(new char[] { '','', '' '' }, StringSplitOptions.RemoveEmptyEntries);



这样可以为您删除逗号和空格.



That removes commas and blanks for you.


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

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