Deleteing a line from a string...

I'm hoping someone might be able to help me with this problem.   What I want to do is use a Regual expression to find matches to a pattern in a rather long string in memory.

However, once that match is found, I wish to DELETE the line the match was found on from the string.

For example
if my string=
"
my cat is in the hat
my bird is in a cage
my fish is looking at the cat
my sheep baa
my bird can talk"

and the pattern is 'bird'
then I wish to delete the two lines containing the 'bird' (because.. you know it's the word)  and return the rest of the string..

example of string AFTER pattern matches:
"
my cat is in the hat
my fish is looking at the cat
my sheep baa
"

How would one go about doing this?

TIA!!!
pogowolfAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wguerramCommented:
do you separate the lines with a vbCrLf?
0
pogowolfAuthor Commented:
Yes.  a NewLine and Carrage return.
0
eekjCommented:
Imports System.Text.RegularExpressions
...

 Dim SourceStr, str As String
 Dim SourceStrArray As String()
 Dim OutputStr As String = ""

 SourceStrArray = str.Split(vbCrLf.ToCharArray())
 For Each str In SourceStrArray
     If Not Regex.Match(str, "[.]*[bB][iI][rR][dD][.]*").Success Then
         OutputStr = OutputStr + str + vbCrLf
     End If
 Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

eekjCommented:
sorry,
 SourceStrArray = SourceStr.Split(vbCrLf.ToCharArray())
'DELETE: SourceStrArray = str.Split(vbCrLf.ToCharArray())
0
pogowolfAuthor Commented:
Thanks eekj,
   I'll check out the code in a moment, I do believe that's what I'm looking for..

Makes me wonder though.. is pattern Matching on a WHOLE string (like 600+ lines long) faster then
searching line by line?
0
wguerramCommented:
eekj gave you the solution i was thinking in...
0
pogowolfAuthor Commented:
I'll accept the answer, though it's not 100% what i was looking for it does work.
0
eekjCommented:
lame
0
pogowolfAuthor Commented:
No, it's not 100%  what I was looking for.  After a little more research and asking around I was able to create a solution:


Dim BlackList as NEW ArrayList
Dim Footer as String = "\r\n"
BlackList.Add(Pattern & Footer)
   
Dim options As RegexOptions = RegexOptions.None
Dim regex As Regex = new Regex(BlackList(0), options)
    Dim input As string = SourceString
    Dim replacement As string = ""
    OutputStr = regex.Replace(input, replacement)
End Sub


The code above speeds up your routine about 25x.
0
eekjCommented:
>>Dim Footer as String = "\r\n"
you need to escape the "\r\n" as "\\r\\n"

the easiest way in that case is just:
OutStr = Regex.Replace(InStr, "[.]*[bB][iI][rR][dD][.]*\\r\\n", "")
0
pogowolfAuthor Commented:
If I might ask, Why is the escape needed?  I thought the \r was already escaped.  wouldn't "\\R" look for a '\' and then an 'r' in the pattern?

0
eekjCommented:
The regular expression \\ matches a single backslash.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.