C# 中的 Uri.EscapeDataString(String) 方法


C# 中的 Uri.EscapeDataString() 方法將字串轉換為其轉義表示形式。

語法

語法如下所示 -

public static string EscapeDataString (string str);

上面,字串 str 是要轉義的字串。

示例

現在讓我們看一個實現 Uri.EscapeDataString() 方法的示例 -

using System;
public class Demo {
   public static void Main(){
      string URI1 = "https://tutorialspoint.tw/index.htm";
      Console.WriteLine("URI = "+URI1);
      string URI2 = "https://tutorialspoint.tw/";
      Console.WriteLine("URI = "+URI2);
      Console.WriteLine("
Escaped string (URI1) = "+Uri.EscapeDataString(URI1));       Console.WriteLine("Escaped string (URI2) = "+Uri.EscapeDataString(URI2));    } }

輸出

這將產生以下輸出 -

URI = https://tutorialspoint.tw/index.htm URI = https://tutorialspoint.tw/
Escaped string (URI1) = https%3A%2F%2Fwww.tutorialspoint.com%2Findex.htm
Escaped string (URI2) = https%3A%2F%2Fwww.tutorialspoint.com%2F

更新於:08-Nov-2019

850 次瀏覽

啟動你的 職業 生涯

透過完成課程獲取認證

開始
廣告
© . All rights reserved.