Murat
Murat

Reputation: 101

split() function is deleting rest of the string after comma

I am using split function to add data to data table from csv file my strings are like this

"50000007;Bxxxx Kxxx - Sxxx Fx. xxxx;423283; ;423292;1; ;700000004;T;"

and I use this code

  x = dt.Rows.Count
    For i As Integer = 0 To x - 1
       Dim Data As String = dt.Rows(i).Item(0)
       Dim words As String() = Data.Split(New Char() {";"c})
       bilgi.Rows.Add(words)
    Next

and its working for thousands of lines but if string come with comma for example

"50000007;Bxxxx**,** Kxxx - Sxxx Fx. xxxx;423283; ;423292;1; ;700000004;T;"

after split my string array only ("50000007","Bxxxx") and rest is gone and continue to next line.

can anyone help me solve this issue?

Upvotes: 0

Views: 93

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27322

Disclaimer: This is more of a comment than an answer so please treat as such

I think the code you posted is not complete because a simple test does not produce the output you describe:

    Dim Data As String = "50000007;Bxxxx**,** Kxxx - Sxxx Fx. xxxx;423283; ;423292;1;          ;700000004;T;"
    Dim words As String() = Data.Split(New Char() {";"c})
    For Each word In words
        Debug.WriteLine("word:" & word)
    Next

Outputs:

word:50000007
word:Bxxxx**,** Kxxx - Sxxx Fx. xxxx
word:423283
word: 
word:423292
word:1
word:          
word:700000004
word:T
word:

Upvotes: 2

Related Questions