is this a bug in c#

Last post 07-06-2009 1:01 AM by tapanrami@hotmail.com. 7 replies.

Sort Posts:

  • is this a bug in c#

    06-26-2009, 2:26 AM
    • Member
      83 point Member
    • ronald_yoh
    • Member since 10-27-2008, 2:37 AM
    • Posts 323

    Hi there,


    i'm trying to do the following in c sharp:

    string str;
    
    str.replace("\\","\");


    I'm getting an error on the second line saying "new line in constant".. apparently replace function in c# can't have a value "\" only.


    any thoughts?

  • Re: is this a bug in c#

    06-26-2009, 2:53 AM

    Hi,

    can you provide the string value in str and which character you want to replace ?

    Always "Mark as Answer" the Post That Solves the problem.Because It helps others to find the solution.
    Mohammad Hussain
    http://mohdhussain.blogspot.com/
  • Re: is this a bug in c#

    06-26-2009, 2:58 AM
    • Participant
      1,507 point Participant
    • Mitesh_Darji
    • Member since 04-17-2008, 8:54 AM
    • Ahmedabad
    • Posts 310

    checkout what is the output in browser not in Code Behind.

    string str = "First\\Second";
    str = str.Replace("\\\\", "\\");
    Response.Write(str);

    Please Mark as Answred If This Blog has Helped You.


    Regards
    Mitesh Darji

  • Re: is this a bug in c#

    06-26-2009, 2:59 AM
    • Member
      315 point Member
    • sureshmdb
    • Member since 05-27-2008, 12:18 PM
    • Baleru
    • Posts 63

    Hi

    use following code insted of str.Replace("\\","\");

    str.Replace("\\\\", "\\");

    '\\' means single '\' in strings

    Suresh Mediboyina



    Mark as answer if my response is useful to you.
  • Re: is this a bug in c#

    06-26-2009, 3:02 AM
    Answer
    • Participant
      1,014 point Participant
    • chandu2chandu1
    • Member since 03-23-2007, 6:06 AM
    • Bangalore, India
    • Posts 233

    That isn't a bug in C#.  That is a escape sequence character available from the days of C.


    string str;

    str.Replace("\\\\","\\");

    or

    str.Replace(@"\\",@"\");



    Since, you need to replace two double slashes to a single slash.  Instead of typing extra slash every time you can place an "@" before your string.


    Imagination is more important than knowledge..
    [Albert Einstein]

    Regards,
    Chandu

    My Blog
  • Re: is this a bug in c#

    06-26-2009, 8:35 AM
    • Participant
      755 point Participant
    • Rimbik
    • Member since 02-25-2009, 6:09 AM
    • Mumbai, India
    • Posts 260

    What about this?

    string str = "\\";
                   char c = (char)92;
                   str =   str.Replace("\\",c.ToString());


    Just for knowledge.

    Soumen, India

    Budhi Hin Tanu Janike, Sumirau Pavan Kumar
    Bal budhi Vidya dehu mohe,Harahu Kalesa Vikar
  • Re: is this a bug in c#

    06-26-2009, 9:34 AM
    • Member
      83 point Member
    • ronald_yoh
    • Member since 10-27-2008, 2:37 AM
    • Posts 323

    I've fixed the problem... the solution would be as to what chandu2chandu1 said..

    thx

  • Re: is this a bug in c#

    07-06-2009, 1:01 AM

    \ is escape sequence char so you cant directly use. you need to use it as the ecape sequence char only.

    Please mark as answer if you find this useful.

    Thanking You
    Tapan
Page 1 of 1 (8 items)