473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Splitting string

Hi

I have a multi-line address field which has each line separated by CRLF. How
can I split this field into individual strings using crlf as separator?

Thanks

Regards
Jan 16 '07 #1
12 3012

String.Split ?

http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OP*************@TK2MSFTNGP06.phx.gbl...
Hi

I have a multi-line address field which has each line separated by CRLF.
How
can I split this field into individual strings using crlf as separator?

Thanks

Regards


Jan 16 '07 #2
dim result As String() = theString.Split(Chr(13))
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
String.Split ?

http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OP*************@TK2MSFTNGP06.phx.gbl...
>Hi

I have a multi-line address field which has each line separated by CRLF.
How
>can I split this field into individual strings using crlf as separator?

Thanks

Regards



Jan 16 '07 #3
"John" <Jo**@nospam.infovis.co.ukschrieb:
I have a multi-line address field which has each line separated by CRLF.
How can I split this field into individual strings using crlf as
separator?
'Microsoft.VisualBasic.Strings.Split' + 'ControlChars.CrLf' is what you are
looking for.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 17 '07 #4
Don't you mean?:

Dim result As String() = theString.Split(New String()
{Environment.NewLine})
"Scott M." <s-***@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...
dim result As String() = theString.Split(Chr(13))
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>
String.Split ?

http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OP*************@TK2MSFTNGP06.phx.gbl...
>>Hi

I have a multi-line address field which has each line separated by CRLF.
How
>>can I split this field into individual strings using crlf as separator?

Thanks

Regards




Jan 17 '07 #5
No, I don't.
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Don't you mean?:

Dim result As String() = theString.Split(New String()
{Environment.NewLine})
"Scott M." <s-***@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...
>dim result As String() = theString.Split(Chr(13))
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>>
String.Split ?

http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OP*************@TK2MSFTNGP06.phx.gbl...
Hi

I have a multi-line address field which has each line separated by
CRLF.
How
can I split this field into individual strings using crlf as separator?

Thanks

Regards




Jan 17 '07 #6
Well, seeing as how the OP has a string with CRLF's in it and want's to
split it on CRLF, how is:

dim result As String() = theString.Split(Chr(13))

going to do that?.

It is going to split the string on CR and leave the LF character at the
beginning of the 2nd and subsequent elements of the resulting array.
"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
No, I don't.
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Don't you mean?:

Dim result As String() = theString.Split(New String()
{Environment.NewLine})
"Scott M." <s-***@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...
>>dim result As String() = theString.Split(Chr(13))
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl.. .

String.Split ?

http://msdn2.microsoft.com/en-us/lib...ing.split.aspx

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OP*************@TK2MSFTNGP06.phx.gbl...
Hi
>
I have a multi-line address field which has each line separated by
CRLF.
How
can I split this field into individual strings using crlf as
separator?
>
Thanks
>
Regards
>
>




Jan 17 '07 #7
John wrote:
I have a multi-line address field which has each line separated by CRLF. How
can I split this field into individual strings using crlf as separator?
For VB 2003, you /have/ to use

Microsoft.VisualBasic.Strings.Split( s, vbCrLf )

Dim x as String _
= "X,Y,Z".Replace( ".", vbCrlf )

? Microsoft.VisualBasic.Strings.Split( x, vbCrLf ).Length
3

The String.Split method /does not/ cater for multiple-character
delimiters, only working with lists of characters, each of which it
treats as a separate delimiter, leaving you with lots of blank entries
in the resulting array).

? String.Split( x, vbCr, vbLf ).Length
5

VB 2005 has a [more] sensible String.Split method that can handle
multiple-character delimiters.

? String.Split( x, New String() { vbCrLf } ).Length
3

HTH,
Phill W.
Jan 17 '07 #8
Yes, I see. I had thought that Chr(13) would get the entire CRLF.

But, in your suggestion, the "New String()" is not needed as the Split
method returns an implied string array anyway. So, it seems the best choice
is a combination of our suggestions:

Dim result As String() = theString.Split(Environment.NewLine)
"Stephany Young" <noone@localhostwrote in message
news:OF**************@TK2MSFTNGP03.phx.gbl...
Well, seeing as how the OP has a string with CRLF's in it and want's to
split it on CRLF, how is:

dim result As String() = theString.Split(Chr(13))

going to do that?.

It is going to split the string on CR and leave the LF character at the
beginning of the 2nd and subsequent elements of the resulting array.
"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>No, I don't.
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>Don't you mean?:

Dim result As String() = theString.Split(New String()
{Environment.NewLine})
"Scott M." <s-***@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...
dim result As String() = theString.Split(Chr(13))
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl. ..
>
String.Split ?
>
http://msdn2.microsoft.com/en-us/lib...ing.split.aspx
>
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:OP*************@TK2MSFTNGP06.phx.gbl...
>Hi
>>
>I have a multi-line address field which has each line separated by
>CRLF.
How
>can I split this field into individual strings using crlf as
>separator?
>>
>Thanks
>>
>Regards
>>
>>
>
>




Jan 17 '07 #9
That would have been cool, Scott, except that in their infinite wisdom, the
powers that be omitted a suitable overload that can take just a string as
the delimiter.

A single char works because the String.Split(char()) overload takes a
ParamArray which can be 1 char or many seperate char but if you feed it
String.Split(ChrW(13), Chr(10)) it wouldn't treat the 2 characters as a
combined entity. Instaed it would split on either CR or LF and still give
incorrect results for this case.

The first overload that takes a string, actually takes an Array of strings
(and not a ParamArray) and so the usage actually needs to be, (in this
case):

Dim result As String() = theString.Split(New String()
{Environment.NewLine}, StringSplitOptions.None)

or:

Dim result As String() = theString.Split(New String()
{Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

Unfortunately, in my haste to point out your error, I still got it wrong in
my first post to this thread. (Consider my wrist slapped.)
"Scott M." <s-***@nospam.nospamwrote in message
news:ei**************@TK2MSFTNGP02.phx.gbl...
Yes, I see. I had thought that Chr(13) would get the entire CRLF.

But, in your suggestion, the "New String()" is not needed as the Split
method returns an implied string array anyway. So, it seems the best
choice is a combination of our suggestions:

Dim result As String() = theString.Split(Environment.NewLine)
"Stephany Young" <noone@localhostwrote in message
news:OF**************@TK2MSFTNGP03.phx.gbl...
>Well, seeing as how the OP has a string with CRLF's in it and want's to
split it on CRLF, how is:

dim result As String() = theString.Split(Chr(13))

going to do that?.

It is going to split the string on CR and leave the LF character at the
beginning of the 2nd and subsequent elements of the resulting array.
"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>No, I don't.
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl.. .
Don't you mean?:

Dim result As String() = theString.Split(New String()
{Environment.NewLine})
"Scott M." <s-***@nospam.nospamwrote in message
news:Oj**************@TK2MSFTNGP06.phx.gbl...
dim result As String() = theString.Split(Chr(13))
>
>
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl.. .
>>
>String.Split ?
>>
>http://msdn2.microsoft.com/en-us/lib...ing.split.aspx
>>
>"John" <Jo**@nospam.infovis.co.ukwrote in message
>news:OP*************@TK2MSFTNGP06.phx.gbl.. .
>>Hi
>>>
>>I have a multi-line address field which has each line separated by
>>CRLF.
>How
>>can I split this field into individual strings using crlf as
>>separator?
>>>
>>Thanks
>>>
>>Regards
>>>
>>>
>>
>>
>
>




Jan 17 '07 #10
Don't you mean?:
>
Dim result As String() = theString.Split(New String()
{Environment.NewLine})

No that is for hairs,

:-)

Cor
Jan 18 '07 #11
John,

I assume that you have a multiline field where the line itself is broken by
CRLFCRLF.

What I do than is first replace all CRLFCRLF by an impossible
charachterrange and than make from the CRLF a csv seperator character
depending on your country proceded and ended with a ", than I change the
impossible charachter back to
"""CRLFCRLF""" this sets than the needed starting and ending " as well.

Cor
Jan 18 '07 #12

"Stephany Young" <noone@localhostwrote in message
news:uw**************@TK2MSFTNGP03.phx.gbl...
Unfortunately, in my haste to point out your error, I still got it wrong
in my first post to this thread. (Consider my wrist slapped.)
*sigh* And never when I'm there... LOL
Jan 25 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: qwweeeit | last post by:
Splitting with RE has (for me!) misterious behaviour! I want to get the words from this string: s= 'This+(that)= a.string!!!' in a list like that considering "a.string" as a word. Python...
5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
4
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
2
by: CharChabil | last post by:
Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow:...
6
by: HMS Surprise | last post by:
The string s below has single and double qoutes in it. For testing I surrounded it with triple single quotes. I want to split off the portion before the first \, but my split that works with...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
4
by: yogi_bear_79 | last post by:
I have a simple string (i.e. February 27, 2008) that I need to split into three parts. The month, day, and year. Splitting into a string array would work, and I could convert day and years to...
37
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.