

/ /// If true, links are given "nofollow" /// attribute public static string ToHtml( this string s, bool nofollow) / /// Returns a copy of this string converted to HTML markup. / public static string ToHtml( this string s) Private static string _linkNoFollow = "" Private static string _paraBreak = "\r\n\r\n" Listing 1: The ToHtml() Extension Method public static class StringMethodExtensions But if you or your users want the ability to submit Web content in plain text, this provides an easy syntax to specify hyperlinks. If you are simply taking unformatted text and displaying it on a Web page, then this special link syntax won't come into play (the double square brackets are unlikely to occur naturally). This produces a hyperlink with Black Belt Coder as the anchor text and as the target URL.

You can also specify two text values in the form ]. So, for example ] produces a hyperlink with as both the anchor text and the target URL. This syntax uses double square brackets ( ]). Because regular tags would be encoded by this method, a special syntax is required to allow users to specify a hyperlink. In addition, this method supports a special syntax for specifying links. And it calls HttpUtility.HtmlEncode() to HTML-encode special characters. It converts single newlines into line breaks (using tags). The ToHtml() method converts blocks of text separated by two or more newlines into paragraphs (using tags).
HOW TO CHANGE TEXT ENCODING HTML CODE
This code adds the ToHtml() method to string variables. Listing 1 shows my ToHtml() extension method. When a Web application needs to display unformatted text that contains multiple lines and/or paragraphs on a Web page, a little more work is required. However, this method won't do anything with line breaks and paragraphs. NET library provides the HttpUtility.HtmlEncode() method to encode special characters so that they will appear as expected in a browser. In these cases, the text must be converted.įortunately, the. This text may be entered by the user or from another source that has not been formatted for HTML. However, sometimes an application needs to display text from a file or database. Characters that have special meaning in HTML must be properly encoded and, since most whitespace is ignored, special tags are required to denote line breaks and paragraphs. When writing text for a Web page, that text must be formatted according to the rules of HTML and XHTML.

HOW TO CHANGE TEXT ENCODING HTML DOWNLOAD
Download Source Code and Demo Project Introduction
