Using the Replace Method


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Using the Replace Method

  1. #1
    Dan Guest

    Using the Replace Method


    In working with VB and VBScript a lot, I'm used to the Replace method being
    able to replace multiple characters: Replace(string,"abc","def"). However,
    with C# it looks like it only accepts one character at a time during a replace
    operation. Without using regular expressions, is there a way to replace
    multiple characters in one pass like with VB?

    Thanks for any help,
    Dan

  2. #2
    David J. Ihne Guest

    Re: Using the Replace Method

    You might try using the StringBuilder class from System.Text:

    str = (new StringBuilder(str)).Replace("abc", "x").ToString();

    David J. Ihne
    Advanced Products
    ACCPAC International, Inc.

    "Dan" <wahlin_NOSPM@home.com> wrote in message
    news:39932cc3$1@news.devx.com...
    >
    > In working with VB and VBScript a lot, I'm used to the Replace method

    being
    > able to replace multiple characters: Replace(string,"abc","def").

    However,
    > with C# it looks like it only accepts one character at a time during a

    replace
    > operation. Without using regular expressions, is there a way to replace
    > multiple characters in one pass like with VB?
    >
    > Thanks for any help,
    > Dan




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center