Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

เมธอด Uri.EscapeDataString() ใน C#

เมธอด Uri.EscapeDataString() ใน C# ใช้สำหรับแปลงสตริงเป็นการแทนค่าในรูปแบบที่หนีบตัวอักษร (escaped representation)

ไวยากรณ์

ไวยากรณ์มีดังนี้:

public static string EscapeDataString (string str);

พารามิเตอร์ str คือสตริงที่ต้องการหนีบตัวอักษร

ตัวอย่าง

ตัวอย่างการใช้งานเมธอด Uri.EscapeDataString():

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

ผลลัพธ์

โค้ดจะแสดงผลดังนี้:

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