Answer to Question #161935 in C# for Skiper

Question #161935

Write a function that takes a string and split it by words to array of strings.


1
Expert's answer
2021-02-07T16:49:00-0500
static void Main(string[] args)
        {
            // Example of program usage
            string text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut enim ad minim veniam...";
            string[] words = Split(text);


            foreach(string s in words)
            {
                Console.WriteLine(s);
            }


            Console.ReadKey();
        }
        // Split method
        public static string [] Split(string text)
        {
            string[] separatingStrings  = { " ", ",", ".", ":", "\t", "\n" };
            return text.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries);
        }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS