Split Function

  • Thread starter Thread starter mannyGonzales
  • Start date Start date
M

mannyGonzales

Hey guys,

Very common task: read a csv file. My data reads as:
"1","2","3",

my code reads this way:

While filename.Peek > -1
instr = filename.ReadLine
indata = Split(instr, ",")
End While

Problem: my values are coming out as ""1""

What's my solution?

Thanks
 
mannyGonzales said:
Very common task: read a csv file. My data reads as:
"1","2","3",

my code reads this way:

While filename.Peek > -1
instr = filename.ReadLine
indata = Split(instr, ",")
End While

Problem: my values are coming out as ""1""

You can use 'Replace' to to get rid of the """, or 'Mid' to cut out the
data part of the string. There are lots of other ways to cope with the problem...
 
mannyGonzales said:
Very common task: read a csv file. My data reads as:
"1","2","3",

my code reads this way:

While filename.Peek > -1
instr = filename.ReadLine
indata = Split(instr, ",")
End While

indata = Split(instr.Replace("""", ""), ",")

Jürgen Beck
MCSD.NET, MCDBA, MCT
www.Juergen-Beck.de
 
mannyGonzales,
In addition to the others comments, I used String.Trim to remove the leading
& trailing quote marks on the string after I did the split in a project I
worked on.

indata = instr.Split(","c)
For index As Integer = 0 To indata.Length -1
indata(index) = indata(index).Trim(""""c)
Next

Not sure why I did the above as opposed to using Replace on the input to
Split. Note my project used the String.Split function that accepts a Char,
rather than the VB Split function that accepts a string.

Hope this helps
Jay
 
Back
Top