Code for Splitting comma separated value and listing as numbered list

Raja
Posted by Raja under C# category on | Views : 6004
If you want to split the .csv file and list as numbered list, you can use following code snippets.


using System.Text;
class MyClass
{
protected void ClickButton(object sender, EventArgs e)
{
string str = txtText.Text.Trim(); // comma separated values
string[] ss = str.Split('\n');
int i = 0;
StringBuilder strB = new StringBuilder();
foreach (string s in ss)
{
i++;
strB.Append(i + " : " + s + "\n");
}
txtResult.Text = strB.ToString(); // write the result into TextBox
}
}


Thanks

Comments or Responses

Login to post response