Thursday, December 3, 2009

Parsing comma separated string

Following is the simple code to parse comma separated string into a string array.
This StringSplitOptions reduces the overhead on developers.
It trims ',' charaters (ie if any , present in the begining or end).
It removes any empty values (ie "Dinesh,,Uthayakumar").

string Name = "Dinesh,Uthayakumar,Din";
string[] fullname = Name.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Console.Write(fullname.Length);

No comments:

Post a Comment