How to handle comma within string

  • Thread starter Thread starter cahmad
  • Start date Start date
C

cahmad

Guest
Hello there,

I have csv file with the following information


1542316.jpg

i used the following code

using (FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.Read))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
do
{
string line = sr.ReadLine();
string[] vals = line.Split(',');
}while (sr.Peek() != -1);
}

Using the above code, i got the following result, (which is this is not what i want)

vals[0] = Test_1

vals[1] = Test 2

vals[2] = t

vals[3] = est

vals[4] = 3

vals[5] = 10

I want the result as below

vals[0] = Test_1

vals[1] = Test 2

vals[2] = t,est,3

vals[3] = 10

The problem is the comma(,) within the string. How to solve this problem?


Thank you.

Continue reading...
 
Back
Top