Replace ' with \' in C# .

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trisko91
    New Member
    • Nov 2012
    • 1

    Replace ' with \' in C# .

    Hi,

    In this variable, i would like to add some \ before every '.

    Code:
    string html = "<a href=\"annee-prochaine.html\">Calendrier de l'annee prochaine</a>"
    
    html=html.Replace("'", "\'"); //No change
    html=html.Replace("\'", "\'"); //No change
    
    html=html.Replace("\'", "\\'"); 
    //html => <a href=\"annee-prochaine.html\">Calendrier de l\\'annee prochaine</a>
    html=html.Replace("\'", @"\'"); 
    //html => <a href=\"annee-prochaine.html\">Calendrier de l\\'annee prochaine</a>

    Any ideas ?

    Thanks!
    Last edited by Rabbit; Nov 26 '12, 05:02 PM. Reason: Please use code tags when posting code.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    What problems or errors are you getting with the code you provided?

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I have no problems with the code on lines 6 and 8. When I print out the values it looks fine to me.

      Comment

      Working...