split vbcrlf

M

merco

hi
i'm reading a file

Dim sr As StreamReader = New StreamReader(FINI)
Dim AllINI As String = sr.ReadToEnd()
sr.Close()

and the i use split to get the rows.
Dim splitedLine() As String
splitedLine = AllINI.Split(vbCrLf)

I get some extra characters at the top of each "SplitedLIne" line:
the char is VbLf.

How can i use split correctly using more than 1 char separator ?

thanks
 
P

Peter Foot [MVP]

The problem is that split works on a char and CrLf is two chars, so it's
splitting on the carriage return leaving the line feed at the beginning of
the next line.
You might find a better alternative in this scenario is to use ReadLine and
place the results into an arraylist which you can then get a fixed size
array from e.g.

Dim al As New ArrayList
Dim sr As New StreamReader(FINI)

Dim row As String = sr.ReadLine()

While Not row Is Nothing
al.Add(row)
row = sr.ReadLine()
End While

sr.Close()

Dim splittedLine() As String = CType(al.ToArray(GetType(String)),
GetType(String()))

Excuse if there are any mistakes, typed the above from memory

Peter
 
M

merco

ok, thanks is this the only way ?

In this case the separators are vbcrlf but somewhere i use "||" or
other characters...

In this i case what can i do ?
 
C

Chance Hopkins

merco said:
ok, thanks is this the only way ?

In this case the separators are vbcrlf but somewhere i use "||" or
other characters...

In this i case what can i do ?

string[] str = System.Text.RegularExpressions.Regex.Split(yourstring, "||");

(p.s. I can't remember if pipes need escaped in regex, you might need to.)
 
S

Stephany Young

You can use the 'old' style Split function which allows 'splitting' based on
a string rasther that a character:

Dim splitedLine() As String = Microsoft.VisualBasic.Split(AllINI, vbCrLf)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top