-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...
pavol.franek
  • 1,396
  • 3
  • 19
  • 42
  • 1
    Use a regex [Get started with regex (stackoverflow)](http://stackoverflow.com/questions/4235445/get-started-with-regular-expression) – Mark Aug 09 '13 at 20:18
  • Sounds like a job for regex. Have you tried anything yourself? Or is this just another code request? – tnw Aug 09 '13 at 20:19
  • A simple `string.Split` seems to be enough..... – I4V Aug 09 '13 at 20:20
  • Yes I try regex but and I dont want full code. I only need idea how I can detect word in big string and then every time when is this word in big string add to list like new item. I am sorry if it sounded like I would like you to do all the work for me, merely seeking at least an idea. – pavol.franek Aug 09 '13 at 20:23

1 Answers1

1

Use String.Split, like this:

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());
}

Note: Trim() will remove any leading and trailing white spaces.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80