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

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!
 
G

Guest

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.
 
A

alexvorn2

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)
 
G

Guest

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.
 

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