Replacing string character

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

    #1

    Replacing string character

    Hi

    How can I replace all occurrences of a character in a string to another
    character?

    Thanks

    Regards


  • Travis Sharpe

    #2
    Re: Replacing string character

    John wrote:
    Hi
    >
    How can I replace all occurrences of a character in a string to another
    character?
    >
    Thanks
    >
    Regards
    >
    >
    Use the .Replace method of the string
    ..Replace("char that will be replaced","char to replace original char")

    Dim temp as string = "ThisStringIsAT est"
    Dim result as string = temp.Replace("T ","$")
    'Replaces every occurence of "T" with "$"

    Comment

    • Dick Grier

      #3
      Re: Replacing string character

      Hi,

      It may sound silly, but...

      Try the string's Replace method. Example:

      Buffer = Buffer.Replace( comecharsequenc e, someothercharse quence)

      Dick
      --
      Richard Grier, MVP
      Hard & Software
      Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
      Edition,
      ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
      2006.
      See www.hardandsoftware.net for details and contact information.


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Replacing string character

        "John" <John@nospam.in fovis.co.ukschr ieb:
        How can I replace all occurrences of a character in a string to another
        character?
        'System.String. Replace', 'Microsoft.Visu alBasic.Strings .Replace',
        'System.Text.Re gularExpression s.Regex.Replace '.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        Working...