Android Question remove html formatting from a string

marcick

Well-Known Member
Licensed User
Longtime User
Hi,
I have this string that contain HTML formatting and need to extract only the text

Turn <b>right</b> onto <b>Via Emanuele Filiberto</b><div style="font-size:0.9em">Go through 1 roundabout</div>

Should be:
Turn right onto Via Emanuele Filiberto Go through 1 roundabout

Is there a quick way to do it ?
 

NJDude

Expert
Licensed User
Longtime User
Try this code:
B4X:
Sub RemoveTags(Text As String) As String

    Dim Pattern, Replacement As String
    Dim m As Matcher

    Pattern = "<[^>]*>"
    Replacement = " "

    m = Regex.Matcher2(Pattern, Regex.CASE_INSENSITIVE, Text)

    Dim r As Reflector
    
    r.Target = m
  
    Return r.RunMethod2("replaceAll", Replacement, "java.lang.String")

End Sub
 
Upvote 0
Top