C# - How to replace question mark with any character

Discussion in 'ASP .Net' started by gogaz, Aug 24, 2004.

  1. gogaz

    gogaz Guest

    Hi there,
    I have a small problem. I need to replace the "?" character from user
    input string to "-". I have tried:

    Regex.Replace(sStr,"\?","-"); //GIVES ERROR
    Regex.Replace(sStr,@"?","-"); //GIVES ERROR
    Regex.Replace(sStr,@"\?","-"); //DOES NOT WORKS AS IT LOOKS FOR "\?"

    Please help!

    Regards
     
    gogaz, Aug 24, 2004
    #1
    1. Advertising

  2. gogaz

    Karl Guest

    str = str.Replace("?" "-");

    If there's a particular reason you need to use a regular expression, let us
    know.

    karl

    "gogaz" <> wrote in message
    news:...
    > Hi there,
    > I have a small problem. I need to replace the "?" character from user
    > input string to "-". I have tried:
    >
    > Regex.Replace(sStr,"\?","-"); //GIVES ERROR
    > Regex.Replace(sStr,@"?","-"); //GIVES ERROR
    > Regex.Replace(sStr,@"\?","-"); //DOES NOT WORKS AS IT LOOKS FOR "\?"
    >
    > Please help!
    >
    > Regards
     
    Karl, Aug 24, 2004
    #2
    1. Advertising

  3. gogaz

    Shiva Guest

    How about String.Replace() ?

    "gogaz" <> wrote in message
    news:...
    Hi there,
    I have a small problem. I need to replace the "?" character from user
    input string to "-". I have tried:

    Regex.Replace(sStr,"\?","-"); //GIVES ERROR
    Regex.Replace(sStr,@"?","-"); //GIVES ERROR
    Regex.Replace(sStr,@"\?","-"); //DOES NOT WORKS AS IT LOOKS FOR "\?"

    Please help!

    Regards
     
    Shiva, Aug 24, 2004
    #3
  4. I agree with Karl on this one. The issue here is the ? has a special meaning
    in Regex. To do what you desire, I believe you would have to use
    Regex.Escape to escape the ? (make it a ? instead of the Regex special
    character ?).

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ************************************************
    Think Outside the Box!
    ************************************************
    "gogaz" <> wrote in message
    news:...
    > Hi there,
    > I have a small problem. I need to replace the "?" character from user
    > input string to "-". I have tried:
    >
    > Regex.Replace(sStr,"\?","-"); //GIVES ERROR
    > Regex.Replace(sStr,@"?","-"); //GIVES ERROR
    > Regex.Replace(sStr,@"\?","-"); //DOES NOT WORKS AS IT LOOKS FOR "\?"
    >
    > Please help!
    >
    > Regards
     
    Cowboy \(Gregory A. Beamer\) [MVP], Aug 24, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. herman
    Replies:
    5
    Views:
    7,633
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Aug 30, 2007
  2. Cirene
    Replies:
    5
    Views:
    596
    Cirene
    May 17, 2008
  3. Enjoy Life

    Replace function for double quotation mark.

    Enjoy Life, Apr 14, 2004, in forum: ASP General
    Replies:
    33
    Views:
    534
    Ray at
    Apr 15, 2004
  4. Harry Ohlsen
    Replies:
    10
    Views:
    255
    Zachary P. Landau
    Feb 8, 2004
  5. Sebastian
    Replies:
    17
    Views:
    361
    Gene Wirchenko
    Feb 4, 2013
Loading...

Share This Page