Your Ad Here

Posted By

boxubi on 07/02/08


Tagged

parse list array String word


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

ad5qa
umang_nine
khouser


convert string to list of words


 / Published in: C#
 

  1. private static List<string> stringToWordArray(string s)
  2. {
  3. List<string> words = new List<string>();
  4. string word;
  5. s = s.ToUpper();
  6. s = s.Trim(',', '.', '"', '-', ' ', ':', ';', '\n', '!', '?');
  7. while (s.Length > 0)
  8. {
  9. if (s.Contains(' '))
  10. {
  11. word = s.Substring(0, s.IndexOf(" "));
  12. s = s.Substring(s.IndexOf(" ") + 1);
  13. s = s.Trim();
  14. }
  15. else
  16. {
  17. word = s;
  18. s = "";
  19. }
  20. word = word.Trim(',', '.', '"', '-', ' ', ':', ';', '\n', '!', '?');
  21. if (word.Length > 0)
  22. words.Add(word);
  23. else
  24. return words;
  25.  
  26. }
  27. return words;
  28. }

Report this snippet  

You need to login to post a comment.