逃離反斜槓我有以下字符串在與string.replace
http://test.site.com\Content\Images\ProductImages\73\700-4aad-be94-e0b79982951f_0_Chrysanthemum__Product_Search.jpg
我想更換string cleartext=imagePath.Replace("\","/");
圖像控制,但反斜線導致一個問題 - 我怎能取代反斜線?
逃離反斜槓我有以下字符串在與string.replace
http://test.site.com\Content\Images\ProductImages\73\700-4aad-be94-e0b79982951f_0_Chrysanthemum__Product_Search.jpg
我想更換string cleartext=imagePath.Replace("\","/");
圖像控制,但反斜線導致一個問題 - 我怎能取代反斜線?
反斜槓是啓動轉義序列的字符串中的特殊字符。您需要「轉義」\,因此您應該使用imagePath.replace(「\\」,「/」)
您可以使用「\」單獨轉義字符串字符,也可以將任何字符串轉換爲字符串字面上加上@
作爲前綴。
此文檔可在MSDN上獲得:http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx。
瞭解C#中字符串工作原理的另一個好資源是:http://csharpindepth.com/Articles/General/Strings.aspx。
替代方法:imagePath.Replace(@「\」,「/」); – 2011-01-26 09:53:52