Formatting strings

  • Thread starter Thread starter Michel Vanderbeke
  • Start date Start date
M

Michel Vanderbeke

Can anyone help me with this: I have a string, containing an amount of
numbers to begin with, then eventually some text, like
strLine = "0476334089 (home number)"

I want to format the numbers en let the text be unchanged, so the result is
like this
0476/33 40 89 (home number)

The numbers must be formatted using a pattern and the text must be left
unchanged.

All suggestions are welcome.
Many thanks and greetings,

Michel
 
Can anyone help me with this: I have a string, containing an amount of
numbers to begin with, then eventually some text, like
strLine = "0476334089 (home number)"

I want to format the numbers en let the text be unchanged, so the result is
like this
0476/33 40 89 (home number)

The numbers must be formatted using a pattern and the text must be left
unchanged.

All suggestions are welcome.
Many thanks and greetings,

Michel

Have you looked into the String.Format method?
 
I did, but I cannot get the result I want.

In the example I gave you, the result must be: three numbers - a slash - two
numbers - a space - two numbers - a space - two numbers - the unchanged
text.

I do not see how I can achieve that with String.Format.

Michel
 
You might use Regular expressions. Something like this

Dim oMatchs As MatchCollection
Dim oReg As New Regex("^(\d{4})(\d{2})(\d{2})(\d{2})\s*(\S*)")
oMatchs = oReg.Matches(TextBox1.Text)
Label1.Text = oReg.Replace(TextBox1.Text, "$1/$2 $3 $4 $5")

This is probabily not anywhere near the best regex pattern but maybe it
could get you started.
Lauren
 
Back
Top