-1

I have one big string with many words and I need every word which start with string stations: add to list like item. Here is example> Its windows 8 store app

var myBigString = myStrings;

myBigString contains this: stations: \"Budatínska\"\nstations: \"Bytčianska\"\n...

How I can in cycle when is word stations: add new item Budatínska to my list of string.

Something like :

List<string> mylist= new List<string>();
foreach(mystring in bigString)
if(mystring=="stations") add.mylist...
4

1 回答 1

1

使用String.Split,像这样:

string source = "stations: ONEstations: TWOstations: THREE";
string[] stringSeparators = new string[] {"stations:"};
string[] result;

result = source.Split(stringSeparators, StringSplitOptions.None);

List<string> mylist = new List<string>();

foreach(string val in result)
{
    mylist.Add(val.Trim());
}

注意:Trim()将删除任何前导和尾随空格。

于 2013-08-09T20:22:32.003 回答