- Home /
How do I step through every other occurance of a word in a string?
Basically I'm trying to split up my long string so that I can put it into a nice hash table. Luckily my string is divided with commas where I want the splits to occur. So far I have code that can go through ALL the words and put them into the keys but I want them obviously to be just every other word. How do I do that?
var words :String[] = stringToConvert.Split(',');
//Sort the keys into the hashtable for(word in stringToConvert)//needs to be every other one, but how?? {
newHashtable.Add(entry.Key ); }
CHeers
Answer by Lab013 · Mar 14, 2011 at 09:10 AM
Regex or creating your own (stripped) lexical parsing function. Either of which wouldn't be too difficult, and depending on how you program it, it may be faster than using split as well. Also, you could just botch every other element of the array.