Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. String.Replace with Escaped Characters

String.Replace with Escaped Characters

Scheduled Pinned Locked Moved C#
htmlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reanalyse
    wrote on last edited by
    #1

    I am being driven mad trying to replace a path name in a string - trying to change an absolute to relative link in HTML code An excerpt of the HTML is below _________________________________________________________________________________________ \r\n

    Forest Heights

    " ______________________________________________________________________________________ I have successfully extracted the filename (C:\\htmlexport\\test_files\\img0.png) and used it to copy and rename the file, but all attempts to change the string in this excerpt using code like string absolutefile; absolutefile=htmlEditorControl1.BodyHtml.Substring(startind-1,endind-startind+5); //extract the file name from path string fname=Path.GetFileName(absolutefile); string ftype=Path.GetExtension(absolutefile); string newdest =@fname; //this works File.Copy(absolutefile,newdest,true); returnstring=htmlEditorControl1.BodyHtml; //following line does not replace the "absolutefile" value with the "fname" value returnstring.Replace(@absolutefile,@fname); fails with no change to the string. Does anyone have any experience with the "escaped" value substitution in a string ? Thanks -- modified at 21:12 Sunday 20th November, 2005

    S 1 Reply Last reply
    0
    • R Reanalyse

      I am being driven mad trying to replace a path name in a string - trying to change an absolute to relative link in HTML code An excerpt of the HTML is below _________________________________________________________________________________________ \r\n

      Forest Heights

      " ______________________________________________________________________________________ I have successfully extracted the filename (C:\\htmlexport\\test_files\\img0.png) and used it to copy and rename the file, but all attempts to change the string in this excerpt using code like string absolutefile; absolutefile=htmlEditorControl1.BodyHtml.Substring(startind-1,endind-startind+5); //extract the file name from path string fname=Path.GetFileName(absolutefile); string ftype=Path.GetExtension(absolutefile); string newdest =@fname; //this works File.Copy(absolutefile,newdest,true); returnstring=htmlEditorControl1.BodyHtml; //following line does not replace the "absolutefile" value with the "fname" value returnstring.Replace(@absolutefile,@fname); fails with no change to the string. Does anyone have any experience with the "escaped" value substitution in a string ? Thanks -- modified at 21:12 Sunday 20th November, 2005

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Reanalyse wrote:

      returnstring.Replace(@absolutefile,@fname);

      I don't know if it's a copy/paste error, but strings are immutable, so Replace doesn't actually doesn't modify the string, instead, it returns a new string with the replacements.

      returnstring = returnstring.Replace(...)

      should work fine. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups