Hello,
I am trying to parse a string on the newline char. I
guess vbCrLf is a string constant. How can I parse my
string - data - on the newline char?
....
data += ASCII.GetString(buffer, 0, bytesRead)
....
Dim parts() As String = data.Split(vbCrLf)
Thanks,
Ron 14 34863
Hi Ron,
I think the Split method of the string object either takes a single char or
an array of chars. If you use the latter overload, .NET will assume that
any of the chars in the array qualify as a separating character, hence if
you pass in CrLf it decides that either Cr OR Lf is a separator. This means
you'll end up with a blank string for every other element in the array of
parts().
The way I always use is the good ol' fashioned VB Split function, as this
does exactly what you want, eg:
Dim parts() As String = Split(data, vbCrLf)
Regards,
Alex Clark
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:17****************************@phx.gbl... Hello,
I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? ... data += ASCII.GetString(buffer, 0, bytesRead) ... Dim parts() As String = data.Split(vbCrLf)
Thanks, Ron
You can use a StringReader to read a string line by line:
Dim sr As new StringReader(sStringToRead)
while sr.peek <> -1
Dim s as string = sr.ReadLine
'Do something with s here
end While
Perhaps this will help you
Thanks. I thought about that, but I thought I would check
to see if maybe I was missing something in vb.net. Guess
I have to import the Microsoft.VisualBasice namespace?
Thanks again,
Ron -----Original Message----- Hi Ron,
I think the Split method of the string object either
takes a single char oran array of chars. If you use the latter overload, .NET
will assume thatany of the chars in the array qualify as a separating
character, hence ifyou pass in CrLf it decides that either Cr OR Lf is a
separator. This meansyou'll end up with a blank string for every other element
in the array ofparts().
The way I always use is the good ol' fashioned VB Split
function, as thisdoes exactly what you want, eg:
Dim parts() As String = Split(data, vbCrLf)
Regards, Alex Clark
"Ron" <an*******@discussions.microsoft.com> wrote in
messagenews:17****************************@phx.gbl... Hello,
I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? ... data += ASCII.GetString(buffer, 0, bytesRead) ... Dim parts() As String = data.Split(vbCrLf)
Thanks, Ron
.
It took me a while to see what you were doing. This is
pretty cool. I will give that a try. I am trying to
steer away from using Microsoft.VisualBasic for the sake
of using DotNet functionality. I will give this a try,
otherwise, I will go with the good'ol VB Split function.
Thanks,
Ron -----Original Message----- You can use a StringReader to read a string line by line:
Dim sr As new StringReader(sStringToRead) while sr.peek <> -1 Dim s as string = sr.ReadLine 'Do something with s here end While
Perhaps this will help you
.
"Ron" <an*******@discussions.microsoft.com> schrieb: Thanks. I thought about that, but I thought I would check to see if maybe I was missing something in vb.net. Guess I have to import the Microsoft.VisualBasice namespace?
This should be done automatically in VB.NET projects. 'Split' is member of
the 'Microsoft.VisualBasic.Strings' module.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks. I thought about that, but I thought I would check
to see if maybe I was missing something in vb.net. Guess
I have to import the Microsoft.VisualBasice namespace?
Thanks again,
Ron -----Original Message----- Hi Ron,
I think the Split method of the string object either
takes a single char oran array of chars. If you use the latter overload, .NET
will assume thatany of the chars in the array qualify as a separating
character, hence ifyou pass in CrLf it decides that either Cr OR Lf is a
separator. This meansyou'll end up with a blank string for every other element
in the array ofparts().
The way I always use is the good ol' fashioned VB Split
function, as thisdoes exactly what you want, eg:
Dim parts() As String = Split(data, vbCrLf)
Regards, Alex Clark
"Ron" <an*******@discussions.microsoft.com> wrote in
messagenews:17****************************@phx.gbl... Hello,
I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? ... data += ASCII.GetString(buffer, 0, bytesRead) ... Dim parts() As String = data.Split(vbCrLf)
Thanks, Ron
.
It took me a while to see what you were doing. This is
pretty cool. I will give that a try. I am trying to
steer away from using Microsoft.VisualBasic for the sake
of using DotNet functionality. I will give this a try,
otherwise, I will go with the good'ol VB Split function.
Thanks,
Ron -----Original Message----- You can use a StringReader to read a string line by line:
Dim sr As new StringReader(sStringToRead) while sr.peek <> -1 Dim s as string = sr.ReadLine 'Do something with s here end While
Perhaps this will help you
.
"Ron" <an*******@discussions.microsoft.com> schrieb: Thanks. I thought about that, but I thought I would check to see if maybe I was missing something in vb.net. Guess I have to import the Microsoft.VisualBasice namespace?
This should be done automatically in VB.NET projects. 'Split' is member of
the 'Microsoft.VisualBasic.Strings' module.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Alex,
Thanks for that, it is obvious, however I did never understand it.
Cor
you could always remove the CR using string.remove(vbcr) and then split on
LF only - eg string.split(vblf).
ie
dim mystringarray() as string =mystring.remove(vbCr).split(vbLf)
Hope this helps..
Simon
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl... It took me a while to see what you were doing. This is pretty cool. I will give that a try. I am trying to steer away from using Microsoft.VisualBasic for the sake of using DotNet functionality. I will give this a try, otherwise, I will go with the good'ol VB Split function.
Thanks, Ron
-----Original Message----- You can use a StringReader to read a string line by line:
Dim sr As new StringReader(sStringToRead) while sr.peek <> -1 Dim s as string = sr.ReadLine 'Do something with s here end While
Perhaps this will help you
.
Alex,
Thanks for that, it is obvious, however I did never understand it.
Cor
you could always remove the CR using string.remove(vbcr) and then split on
LF only - eg string.split(vblf).
ie
dim mystringarray() as string =mystring.remove(vbCr).split(vbLf)
Hope this helps..
Simon
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl... It took me a while to see what you were doing. This is pretty cool. I will give that a try. I am trying to steer away from using Microsoft.VisualBasic for the sake of using DotNet functionality. I will give this a try, otherwise, I will go with the good'ol VB Split function.
Thanks, Ron
-----Original Message----- You can use a StringReader to read a string line by line:
Dim sr As new StringReader(sStringToRead) while sr.peek <> -1 Dim s as string = sr.ReadLine 'Do something with s here end While
Perhaps this will help you
.
Ron,
As Alex stated, String.Split splits based on individual characters. If you
want to split based on words I would recommend Strings.Split or RegEx.Split.
There are three Split functions in .NET:
Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.
Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.
Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.
NOTE: Microsoft.VisualBasic *is* "DotNet functionality"! There is little
real reason to avoid it altogether. Some classes, such as
Microsoft.VisualBasic.Collection, I avoid altogether as most of the time it
is TOO general. I try not to mix Microsoft.VisualBasic.Strings functions
with System.String methods that take or return indexes, as VB.Strings uses
base 1 indexes, while System.String uses base 0 indexes, and this mixing
could lead to obscure bugs... VB.Split is one method I will use as
System.String currently does not have an actual equivalent (VS.NET 2005, aka
Whidbey, due out later in 2005, does have a String.Split http://msdn2.microsoft.com/library/tabh47cf.aspx method that works on
words).
Hope this helps
Jay
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:17****************************@phx.gbl... Hello,
I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? ... data += ASCII.GetString(buffer, 0, bytesRead) ... Dim parts() As String = data.Split(vbCrLf)
Thanks, Ron
Ron,
As Alex stated, String.Split splits based on individual characters. If you
want to split based on words I would recommend Strings.Split or RegEx.Split.
There are three Split functions in .NET:
Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.
Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.
Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.
NOTE: Microsoft.VisualBasic *is* "DotNet functionality"! There is little
real reason to avoid it altogether. Some classes, such as
Microsoft.VisualBasic.Collection, I avoid altogether as most of the time it
is TOO general. I try not to mix Microsoft.VisualBasic.Strings functions
with System.String methods that take or return indexes, as VB.Strings uses
base 1 indexes, while System.String uses base 0 indexes, and this mixing
could lead to obscure bugs... VB.Split is one method I will use as
System.String currently does not have an actual equivalent (VS.NET 2005, aka
Whidbey, due out later in 2005, does have a String.Split http://msdn2.microsoft.com/library/tabh47cf.aspx method that works on
words).
Hope this helps
Jay
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:17****************************@phx.gbl... Hello,
I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? ... data += ASCII.GetString(buffer, 0, bytesRead) ... Dim parts() As String = data.Split(vbCrLf)
Thanks, Ron This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Grayson |
last post by:
I have a need for an "Eval" function and found the perfect sample
The problem is it doesn't like "IsDate" being fed into it.
Any Ideas? seems like a missing reference, but I can't figure it out......
|
by: jhwagner |
last post by:
I need to use double data entry with an MS Access database. I have
read many arguments and reasons against this on this group but I have
to do this. I have seen various tips on how this can be...
|
by: Mark Waser |
last post by:
Hi all,
I'm trying to post multipart/form-data to a web page but seem to have
run into a wall. I'm familiar with RFC 1867 and have done this before (with
AOLServer and Tcl) but just can't seem...
|
by: Microsoft |
last post by:
I have a multine list that I would like to split into an array. I paste it
into a richtext box and go from there, but it just makes the first part of
the array the whole list with little boxes...
|
by: Jody L. Whitlock |
last post by:
Okay, working on project #2 while in the interim of project #1. anyhew,
this project is a Async socket client, so, lemme give the background of how
things are connecting and such:
Private Sub...
|
by: Ben |
last post by:
Hi
I am creating a dynamic function to return a two dimensional array from a
delimeted string.
The delimited string is like:
field1...field2...field3...
field1...field2...field3......
|
by: Kerry |
last post by:
Please help if you can.
I have a web form that has a multiline input box 30 columns by 15 rows. The
maximum length of a user's entry can be 450 characters. I need to read this
data into a...
|
by: Jan |
last post by:
Hello,
I want to send some simple strings to com1 using vb2005. I want to read
it
in Hyperterminal.
I succeeded to send some data en read it in Hyperterminal, only the data
I
received is not...
|
by: Gilberto |
last post by:
Hello,
I have a couple of forms using the code to FIND AS YOU TYPE from Allen Browne (http://allenbrowne.com/AppFindAsUType.html). It worked PERFECTLY until yesterday when i splitted the db into...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |