We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

boxubi on 07/02/08


Tagged

parse list array String word


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

ad5qa


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.