Split Function in c# not working properly -
static void main(string[] args) { string var = ",a,,,b,,c"; string[] members = var.split(','); foreach (string member in members) { console.writeline(member); } console.writeline(members.length); console.readline(); }
the output of above code is
a b c 7
the 7 length of array
, question when passed ','
in parameters of split function.
so why takes initial ',' space . , why takes 2 out of 3 ',' space after . , why takes 1 out of 2 ',' space after b ?
the answer question is, not space empty string
string
can empty , seeing space.
,,
<- after ,
have nothing, split method adds empty string.
if want remove this, have put after ','
stringsplitoptions
var.split(new char [] {','}, stringsplitoptions.removeemptyentries);
doc: https://msdn.microsoft.com/pl-pl/library/tabh47cf(v=vs.110).aspx
Comments
Post a Comment