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

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -