[ACCEPTED]-Using .Split to remove empty entries-split

Accepted answer
Score: 21

Well, the first parameter to the Split function 7 needs to be an array of strings or characters. Try:

TextBox1.Text.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries).Length

You 6 might not have noticed this before when 5 you didn't specify the 2nd parameter. This 4 is because the Split method has an overload which 3 takes in a ParamArray. This means that 2 calls to Split("string 1", "string 2", "etc") auto-magically get converted into 1 a call to Split(New String() {"string 1", "string 2", "etc"})

Score: 7

Try:

TextBox1.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length 

0

Score: 3

This is what I did:

TextBox1.Text = "1 2 3  5 6"
TextBox1.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length

Result: Length = 5

0

Score: 1
// char array is used instead of normal char because ".Split()"
// accepts a char array
char[] c = new char[1];
//space character in array
c[0] = ' ';
// a new string array is created which will hold whole one line
string[] Warray = Line.Split(c, StringSplitOptions.RemoveEmptyEntries);

0

More Related questions