String.Replace with Escaped Characters
-
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 -
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, 2005Reanalyse 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