I can replace the text that is between "*" and "*" in a text file?

  • Thread starter Thread starter alexvorn2
  • Start date Start date
A

alexvorn2

Hi! I use VB 2008 and I want to ask you how I can replace the text
that is between "*" and "*" in a text file?
If text file contains this:
*dog*
*cat*
*bird*
*lion*
*something*
.....end of file....
I want that the code will replace *dog* with *animal*,
*cat* with *animal* too
*lion* with *animal*
etc...
Thanks!
 
Hi! I use VB 2008 and I want to ask you how I can replace the text
that is between "*" and "*" in a text file?
If text file contains this:
*dog*
*cat*
*bird*
*lion*
*something*
....end of file....
I want that the code will replace *dog* with *animal*,
*cat* with *animal* too
*lion* with *animal*

Yes, you can use regular expressions to do this sort of ting.


I think \*\w\* should be able to find all matches.
 
Yes, you can use regular expressions to do this sort of ting.

I think \*\w\* should be able to find all matches.

Hi, but what I need to do to make this code to work?
For example this code: (it not works)

Dim TestString As String = "Sh*o*pping List"
' Returns "Shipping List".
Dim aString As String = Replace(TestString, "\*\w\* ", "i")
MsgBox(aString)
 
Hi, but what I need to do to make this code to work?
For example this code: (it not works)

Dim TestString As String = "Sh*o*pping List"
' Returns "Shipping List".
Dim aString As String = Replace(TestString, "\*\w\* ", "i")
MsgBox(aString)

You have to use Regular Expressions... System.Text.RegularExpressions
Namespace.
 
Back
Top