MrMistreater

Convert string to list of words

May 21st, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment