Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 159, comments - 0, trackbacks - 0

My Links

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2015!

Pre-order VB 2015 Unleashed Pre-order my new book "Visual Basic 2015 Unleashed". Click for more info!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

Follow me on Twitter!

CodePlex download Download my open-source projects from CodePlex!

Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

Converting text to HTML with Visual Basic

I have found this interesting article on CodeProject where they explain how to create a method that converts a String to HTML format by invoking the HttpUtility.HtmlEncode method, but the explanation is C# only.

This approach is okay in Web projects, and I want to provide a Visual Basic translation:

        Public Shared Function HtmlEncode(text As String) As String
            Dim chars As Char() = HttpUtility.HtmlEncode(text).ToCharArray()
            Dim result As New System.Text.StringBuilder(text.Length + CInt(text.Length * 0.1))

            For Each c As Char In chars
                Dim value As Integer = Convert.ToInt32(c)
                If value > 127 Then
                    result.AppendFormat("&#{0};", value)
                Else
                    result.Append(c)
                End If
            Next

            Return result.ToString()
        End Function

It can be useful 

Alessandro

Print | posted on venerdì 9 dicembre 2011 12:01 | Filed Under [ Visual Basic ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 5 and 6 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET