[ACCEPTED]-Using .Split to remove empty entries-split
Accepted answer
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"})
Try:
TextBox1.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length
0
This is what I did:
TextBox1.Text = "1 2 3 5 6"
TextBox1.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length
Result: Length = 5
0
// 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
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.