Android Question [Resolved] i have some special char in the text how to make it normal - Html Decoder

kmap

Member
Licensed User
Longtime User
Creating a Just Culture: A Nurse Leader’s Guide

this is the text which i need to convert to normal text

’

is there any function that converts all such char into normal char

like ?,',<,>

all these are showing in the text as a number.

if anyone knows please help
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code (note that it wasn't test thoroughly):
B4X:
Sub HtmlDecoder(encoded As String) As String
   Dim sb As StringBuilder
   sb.Initialize
   Dim xmlEntities As Map = CreateMap("quot": QUOTE, "lt": "<", "gt": ">", "amp": "&")
   Dim m As Matcher = Regex.Matcher("&(#\d+|quot|lt|gt|amp);", encoded)
   Dim index As Int
   Do While m.Find
     sb.Append(encoded.SubString2(index, m.GetStart(0)))
     index = m.GetEnd(0)
     If xmlEntities.ContainsKey(m.Group(1)) Then
       sb.Append(xmlEntities.Get(m.Group(1)))
     Else
       Dim rawCodepoint As String = m.Group(1).SubString(1)
       If IsNumber(rawCodepoint) Then
         sb.Append(Chr(rawCodepoint))
       Else
         sb.Append(m.Match)
       End If
     End If
   Loop
   If index < encoded.Length Then sb.Append(encoded.SubString(index))
   Return sb.ToString
End Sub
 
Upvote 0
Top