从字符串数组替换字符串的所有出现 [英] Replace all occurences of a string from a string array
本文介绍了从字符串数组替换字符串的所有出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串数组,如:
的String []项目= {一,二,三,一,二,一};
我想一次更换零所有的人。
那么项目应该是:
{零,二,三,零,二,零};
我找到了一个解决方案我如何更换在一个字符串数组项?。
但是,这只能更换一次出现。这是最好的方法/步骤来代替所有出现?
任何帮助AP preciated。
解决方案
的String []项目= {一,二,三,一,二,一};
项目= items.Select(!?s => S =一S:零)ToArray的()。
从这里 找到答案
感谢所有
I have a string array like:
string [] items = {"one","two","three","one","two","one"};
I would like to replace all ones with zero at once. Then items should be:
{"zero","two","three","zero","two","zero"};
I found one solution How do I replace an item in a string array?.
But it will replace the first occurrence only. Which is the best method/approach to replace all occurrences?
Any help appreciated.
解决方案
string [] items = {"one","two","three","one","two","one"};
items = items.Select(s => s!= "one" ? s : "zero").ToArray();
Found answer from here..
Thanks all
这篇关于从字符串数组替换字符串的所有出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文