String Replace
-
20 สิงหาคม 2555 11:40
In server.mapth I get
imagepath=E:\\Imageparse\\Test\\Test\\image\\babby.jpeg
I want to replace as
imagepath.Replace("\\Test\\Test","\\Test");
Can any on help
Thanks in advance
- ย้ายโดย Ilya TumanovMicrosoft, Moderator 20 สิงหาคม 2555 15:44 (From:.NET Compact Framework)
ตอบทั้งหมด
-
20 สิงหาคม 2555 16:52
Hello, your code is right. did you try following
string imagepath="E:\\Imageparse\\Test\\Test\\image\\babby.jpeg" imagepath = imagepath.Replace("\\Test\\Test","\\Test");please Mark as the Answer, If this answers your question. If this post is helpful, please vote as helpful.
- เสนอเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 21 สิงหาคม 2555 7:25
- ทำเครื่องหมายเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 28 สิงหาคม 2555 8:11
-
20 สิงหาคม 2555 17:47
I would even suggest you to use @ simbol which replaces double \ with a single one:
string imagepath = @"E:\Imageparse\Test\Test\image\babby.jpeg"; imagepath = imagepath.Replace("Test\\Test","Test");
Mitja
- เสนอเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 21 สิงหาคม 2555 7:25
- ทำเครื่องหมายเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 28 สิงหาคม 2555 8:12
-
20 สิงหาคม 2555 22:23
I would even suggest you to use @ simbol which replaces double \ with a single one:
string imagepath = @"E:\Imageparse\Test\Test\image\babby.jpeg"; imagepath = imagepath.Replace("Test\\Test","Test");
Mitja
Hi Mitja,
why not use the @ Symbol in the Raplace-Line then?
imagepath = imagepath.Replace(@"Test\Test","Test");
like:
string s = @"a\b\test\test\c\d"; s = s.Replace(@"\test\test", @"\test"); MessageBox.Show(s);Regards,
Thorsten
- เสนอเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 21 สิงหาคม 2555 7:24
- ทำเครื่องหมายเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 28 สิงหาคม 2555 8:12
-
21 สิงหาคม 2555 3:24
You must aware that if you look at variable values in Visual Studio's Debug mode.
You will see double backslash in C# environment.For example, if the variable has value "a\b\c",
While Visual Studio will display it as "a\\b\\c", the actual value is still "a\b\c".From your code I guess that it should be:
string imagePath; // use camelCase for local variables. imagePath = Server.MapPath("~\test\image\babby.jpeg"); // you must assign the result of Replace back to imagePath imagePath = imagePath.Replace(@"\test\test", @"\test");HTH
- แก้ไขโดย surrealistMVP 21 สิงหาคม 2555 3:26
- เสนอเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 21 สิงหาคม 2555 7:24
- ทำเครื่องหมายเป็นคำตอบโดย Jason Dot WangMicrosoft, Moderator 28 สิงหาคม 2555 8:12
-
21 สิงหาคม 2555 7:42
why not use the @ Symbol in the Raplace-Line then?
Ups, I meant that too, but I forgot to change it. Thx for remining me!
string imagepath = @"E:\Imageparse\Test\Test\image\babby.jpeg"; imagepath = imagepath.Replace(@"Test\Test","Test");
Mitja
-
21 สิงหาคม 2555 18:51
Maybe you can avoid replacing here, by adjusting the code that executes ‘MapPath’, so that you will get the required path.
- แก้ไขโดย Viorel_MVP 21 สิงหาคม 2555 18:51