Formatting strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michel Vanderbeke

    #1

    Formatting strings

    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




  • zacks@construction-imaging.com

    #2
    Re: Formatting strings

    On Jun 1, 11:26 am, "Michel Vanderbeke" <michel.vanderb ...@skynet.be>
    wrote:
    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?

    Comment

    • Michel Vanderbeke

      #3
      Re: Formatting strings

      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



      <zacks@construc tion-imaging.comschr eef in bericht
      news:1180711995 .030376.10390@o 5g2000hsb.googl egroups.com...
      On Jun 1, 11:26 am, "Michel Vanderbeke" <michel.vanderb ...@skynet.be>
      wrote:
      >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?
      >

      Comment

      • Lauren

        #4
        Re: Formatting strings

        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(Te xtBox1.Text)
        Label1.Text = oReg.Replace(Te xtBox1.Text, "$1/$2 $3 $4 $5")

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

        "Michel Vanderbeke" <michel.vanderb eke@skynet.bewr ote in message
        news:e3pLEFGpHH A.588@TK2MSFTNG P06.phx.gbl...
        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
        >
        >
        >
        >

        Comment

        Working...