Replacing characters in WEB text

Tech-Archive recommends: Speed Up your PC by fixing your registry




Dear friend as a routine to replace special character when one has to
output text on a web page (client side) I have used this one as a quick
and dirty way:

---------------------------------------------------------------------

Dim WebSymbols As String() = New String() { _
"&", "&", _
">", ">", _
"<", "&lt;", _
(...Long list omitted...)
"û", "&ucirc;", _
"ü", "&uuml;", _
"ý", "&yacute;", _
"þ", "&thorn;", _
"ÿ", "&yuml;", _
" ", "&nbsp;", _
vbCrLf, "<br>" _
}

'Note: &amp; must precede all, <br> must follow &gt; &lt;

Public Function FixStringForWEB(ByVal Text As String) As String

Dim WebText As New System.Text.StringBuilder(Text)
For i As Integer = 0 To WebSymbols.Length - 1 Step 2
WebText = WebText.Replace(WebSymbols(i), WebSymbols(i + 1))
Next i
Return WebText.ToString

End Function

-------------------------------------------------------------

I feel this method is unsatisfactory and ackward. I am wondering
if anyone can suggest a method more elegant and especially faster
(although the above is not that slow).

-Pamela

.



Relevant Pages

  • HTTPPost WebException Connection Closed
    ... It always works the first time and then generates the following ... The article also suggests setting KeepAlive=false on the client ... Public Function PostPage(ByVal url As String, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Serialize a Dataset
    ... Public Function VenueData(ByVal VenueID As Integer) As DataSet ... with a .NET client. ... Was trying to return as the string of a function call. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Returning different types of objects in a column in a dataset
    ... webservice that returns an object based on the parameter, and my client ... Here is some test code for that: ... Public Function GetDataSet(ByVal ObjectType As String) As DataSet ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Singleton Objects
    ... But I continue to have the same problem,i.e., message from one client ... >> Private Shared message As String ... >> End Sub ... >> Public Function receiveAs String ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: converting the use of interfaces under vb6 to vb.net
    ... VB6. ... | Public Function NewEnum() As IUnknown ... |> Public Interface IReadonlyPerson ... |> | Public Property Get FirstNameas String ...
    (microsoft.public.dotnet.languages.vb)