December 2007
Intermediate to advanced
896 pages
19h 57m
English
You need to transform data for use in web operations from escaped to unescaped format or vice versa for proper transmission. This escaping and unescaping should follow the format outlined in RFC 2396—Uniform Resource Identifiers (URI): Generic Syntax.
Use the Uri class static methods for escaping and unescaping data and Uris.
To escape data, use the static Uri.EscapeDataString method, as shown here:
string data = "<H1>My html</H1>";
Console.WriteLine("Original Data: {0}",data);
Console.WriteLine( );
// public static string EscapeDataString(string stringToEscape);
string escapedData = Uri.EscapeDataString(data);
Console.WriteLine("escaped Data: {0}",escapedData);
Console.WriteLine( );
// Output from above code is
//
// Original Data: <H1>My html</H1>
//
// Escaped Data: %3CH1%3EMy%20html%3C%2FH1%3ETo unescape the data, use the static Uri.UnescapeDataString method:
// public static string UnescapeDataString( string stringToUnescape);
string unescapedData = Uri.UnescapeDataString(escapedData);
Console.WriteLine("unescaped Data: {0}", unescapedData);
Console.WriteLine( );
// Output from above code is
//
// Unescaped Data: <H1>My html</H1>To escape a Uri, use the static Uri.EscapeUriString method:
string UriString = "http://user:password@localhost:8080/www.abc.com/" + "home page.htm?item=1233;html=<h1>Heading</h1>#stuff"; Console.WriteLine("Original Uri string: {0}",UriString); Console.WriteLine( ); // public static string ...Read now
Unlock full access