gwt
gwt

Reputation: 2423

How can I split a string that has three spaces as its separators?

I have written many lines to a text file and I have divided each line into parts by putting three spaces between parts. Here is an example of a line :

1   khashayar   home

Now I want to read and split each line by using

 arraytobeprinted = ss.Split('   ');

but I get this error:

There are too many characters in character literals

How can I fix this ?

Upvotes: 0

Views: 136

Answers (4)

Habib
Habib

Reputation: 223402

You can try String.Split Method (String[], StringSplitOptions) for the same result.

string[] array2 = ss.Split(new string[]{"   "}, StringSplitOptions.None);

Upvotes: 0

mortb
mortb

Reputation: 9869

Try this: ss.Split(new string [] {" "}, StringSplitOptions.None);

Upvotes: 3

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9950

Use ss.Split(null) or ss.Split(new char[0]), this will solve your problem easiest way.

Happy Coding!!!

Upvotes: 0

Kristof Claes
Kristof Claes

Reputation: 10941

You're passing a character as a splitting delimiter. Try passing a string like this:

var parts = ss.Split(new[] { "   " }, StringSplitOptions.None);

Upvotes: 3

Related Questions