C# split a string based on space into an array

Hi I am trying to split a string based on space into string of array (C#.net)

inputString.Split(" "c) throwing an error. Can you help?

Thank you,

Hi @A_Learner,

In C#, use inputString.Split(' ') instead of " "c which is VB syntax. The Split method requires a char or string[] in C#. Example: string[] result = inputString.Split(' ');.

Thank you, Still getting error.
“Expression tree may not contain a call or invocation that uses optional arguments”

inputString.Split() working. But if there is more than one space, how to remove. For example, “Hi there how are you”?

I am getting space as second token if I split. I need to get there.

Thank you,

String.split(" ", String.SplitOptions.RemoveEntryEntries) working. Thank you.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.