Extracting Parts of a String

T

thomasc

Hello,

I have a question about manipulating string in VB.NET2003.

I have a string that looks as follows:
MyString = "1st garbage blah, blah.. " & vbCrLf & _
"==============================" & vbCrLf & _
"2nd garbage blah, blah.. " & vbCrLf & _
"==============================" & vbCrLf & _
"3rd garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"4th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"5th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"6th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"7th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"8th garbage blah, blah.. " & vbCrLf


From this string, I would like to get rid of all the separator lines
shown below:
"==============================" & vbCrLf & _
"------------------------------" & vbCrLf & _

And make a new string that contains the contents of MyString without
those separator lines. Like this:
NewString = "1st garbage blah, blah.. " & vbCrLf & _
"2nd garbage blah, blah.. " & vbCrLf & _
"3rd garbage blah, blah.. " & vbCrLf & _
"4th garbage blah, blah.. " & vbCrLf & _
"5th garbage blah, blah.. " & vbCrLf & _
"6th garbage blah, blah.. " & vbCrLf & _
"7th garbage blah, blah.. " & vbCrLf & _
"8th garbage blah, blah.. " & vbCrLf

I've been digging String methods for a while but still could not find
out how I can do this operation.
Can anyone give me an idea as to how to do this operation?

Thank you very much in advance!
 
A

Armin Zingler

thomasc said:
Hello,

I have a question about manipulating string in VB.NET2003.

I have a string that looks as follows:
MyString = "1st garbage blah, blah.. " & vbCrLf & _
"==============================" & vbCrLf & _
"2nd garbage blah, blah.. " & vbCrLf & _
"==============================" & vbCrLf & _
"3rd garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"4th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"5th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"6th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"7th garbage blah, blah.. " & vbCrLf & _
"------------------------------" & vbCrLf & _
"8th garbage blah, blah.. " & vbCrLf


From this string, I would like to get rid of all the separator lines
shown below:
"==============================" & vbCrLf & _
"------------------------------" & vbCrLf & _

And make a new string that contains the contents of MyString without
those separator lines. Like this:
NewString = "1st garbage blah, blah.. " & vbCrLf & _
"2nd garbage blah, blah.. " & vbCrLf & _
"3rd garbage blah, blah.. " & vbCrLf & _
"4th garbage blah, blah.. " & vbCrLf & _
"5th garbage blah, blah.. " & vbCrLf & _
"6th garbage blah, blah.. " & vbCrLf & _
"7th garbage blah, blah.. " & vbCrLf & _
"8th garbage blah, blah.. " & vbCrLf

I've been digging String methods for a while but still could not
find out how I can do this operation.
Can anyone give me an idea as to how to do this operation?

Thank you very much in advance!

Use the String's Replace method. Replace "-" by "" (String.Empty). Mind that
Replace is a function returning a new String.


Armin
 
A

Armin Zingler

Armin Zingler said:
Use the String's Replace method. Replace "-" by "" (String.Empty).
Mind that Replace is a function returning a new String.

Forget it...

Better:

s = s.Replace("==============================" & vbCrLf, String.Empty)
s = s.Replace("------------------------------" & vbCrLf, String.Empty)


Armin
 

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