removeing leading zeros in a text string (not a numeric field)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Henry

    removeing leading zeros in a text string (not a numeric field)

    Say I have a text string like

    "0002323235-3434-3545" and I want to remove the leading zeros, would a
    regular expression work here? sorry I haven't worked with regex's that much
    and still need to get caught up on them :) if so how would you go about
    doing that? thanks!


  • Marina

    #2
    Re: removeing leading zeros in a text string (not a numeric field)

    Check out the TrimStart method of the string class. You pass it a character
    array of characters to remove - in this case, the array will have one
    character, the "0".

    "Brian Henry" <brianiup[nospam]@adelphia.net> wrote in message
    news:eX5Cx6fMEH A.3664@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Say I have a text string like
    >
    > "0002323235-3434-3545" and I want to remove the leading zeros, would a
    > regular expression work here? sorry I haven't worked with regex's that[/color]
    much[color=blue]
    > and still need to get caught up on them :) if so how would you go about
    > doing that? thanks!
    >
    >[/color]


    Comment

    • Armin Zingler

      #3
      Re: removeing leading zeros in a text string (not a numeric field)

      "Brian Henry" <brianiup[nospam]@adelphia.net> schrieb[color=blue]
      > Say I have a text string like
      >
      > "0002323235-3434-3545" and I want to remove the leading zeros, would
      > a regular expression work here? sorry I haven't worked with regex's
      > that much and still need to get caught up on them :) if so how would
      > you go about doing that? thanks![/color]

      msgbox "0002323235-3434-3545".trimstart ("0"c)


      --
      Armin

      How to quote and why:



      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: removeing leading zeros in a text string (not a numeric field)

        * "Brian Henry" <brianiup[nospam]@adelphia.net> scripsit:[color=blue]
        > "0002323235-3434-3545" and I want to remove the leading zeros, would a
        > regular expression work here?[/color]

        I would use this code:

        \\\
        Dim s As String = "000012"
        MsgBox(s.TrimSt art("0"c))
        ///

        --
        Herfried K. Wagner [MVP]
        <URL:http://dotnet.mvps.org/>

        Comment

        • Brian Henry

          #5
          Re: removeing leading zeros in a text string (not a numeric field)

          thanks everyone, didn't realize you could trim characters like that


          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          news:c78lo9$11s 81$4@ID-208219.news.uni-berlin.de...[color=blue]
          > * "Brian Henry" <brianiup[nospam]@adelphia.net> scripsit:[color=green]
          > > "0002323235-3434-3545" and I want to remove the leading zeros, would a
          > > regular expression work here?[/color]
          >
          > I would use this code:
          >
          > \\\
          > Dim s As String = "000012"
          > MsgBox(s.TrimSt art("0"c))
          > ///
          >
          > --
          > Herfried K. Wagner [MVP]
          > <URL:http://dotnet.mvps.org/>[/color]


          Comment

          Working...