如何分割在C#中的字符串 [英] How to split a string in C#
问题描述
我有像
"List_1 fooo asdf List_2 bar fdsa XList_3 fooo bar"
和列表<弦乐>
像
List<String> l_lstValues = new List<string> { "List_1", "XList_3", "List_2" };
我需要基于 l_lstValues 值来分割字符串code>。
所以,分割后的子串会像
So the splitted substrings will be like
List_1 fooo asdf
List_2 bar fdsa
XList_3 fooo bar
请发布我一个办法做到这一点$在进b $ b谢谢
Please post me a way to do this Thanks in advance
推荐答案
您已经使用MSDN上这种拆分方法,你有到列表中传递到一个数组,然后,你必须通过作为分割数组的一个参数。
You have to use this split method on msdn, you have to pass your List into an array and then, you have to pass as a parameter of the split that array.
我离开你这里的链接
的http:/ /msdn.microsoft.com/en-us/library/tabh47cf(v=VS.90).aspx
如果你想十个分量的话你'再劈开,你将不得不遍历结果数组,然后添加词语列表,如果你有字符串,并在列表中的顺序相同。
If you want to mantain the words you're splitting with, you will have to iterate the resulted array and then add the words in your list, if you have the same order in the string and in the list.
如果订单是未知的,你每亩用的indexOf来在列表中找到的话,分裂手动字符串。
If the order is unknown, you mus use indexOf to locate the words in the list and split the string manually.
见
这篇关于如何分割在C#中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!