pick numbers from a string

bpnlsu

Member
Joined
Sep 23, 2006
Messages
8
Programming Experience
Beginner
Hi Friends,

Suppose, if string is
Dim str as String = "2 hand 10 fingers 1 head"

I would like to print the sentence as "0.0#2 hand 0.01#0 finger 0.0#1 head"

ie each number in string should be replaced as 0.0#number

Can anybody help me with this... ?

Thanks!
Basky
 
I made the word INPUT in the original statement bold to catch your eye; it is at this point that you would supply the name of a string variable that contains the sentence within which you wish the replacement to be performed

i.e.
Dim input as String = "2 heads are better than 1 even if 1 is a sheep's head"
Dim result as String = System.Text.RegularExpressions.Regex.Replace(input, "(\\d+)", "0.0#$1")

MessageBox.Show(result)

--> Messagebox appears bearing string "0.0#2 heads are better than..."
 
Back
Top