Android Question Paste html tags in html

Hello everyone.
I made a project that took a string from an edit box and converted it to html. This program was working well until I put html tags in the edit box, the program stopped. How to put html tags in html.

B4X:
sb.Append($"<html><head><title>Title</title></head><body><p>"$)
///////////////
sb.Append($"<html><head><title>Title</title></head><body><p>this is a sample that how to make html</p></body></html>"$)
/////////////
sb.Append($"</p></body></html>"$)
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
the program stopped
Post the full error!
Upload a small project showing the problem.

Away from that i dont see how the code above will crash the app.
 
Upvote 0

emexes

Expert
Licensed User
I made a project that took a string from an edit box and converted it to html. This program was working well until I put html tags in the edit box, the program stopped. How to put html tags in html.

Rather than you (or your users) have to manually type those HTML entity codes, I'd run the sample HTML through a function eg:

B4X:
Sub SampleHtml(H As String) As String

    Dim S As String = H
 
    S = S.Replace($"<"$, "&lt;")
    S = S.Replace($">"$, "&gt;")
    S = S.Replace($"""$, "&quot;")
    S = S.Replace($"'"$, "&apos;")
    S = S.Replace($"&"$, "&amp;")
 
    Return S
 
End Sub

and then I think your code would like like:

B4X:
sb.Append($"<html><head><title>Title</title></head><body><p>"$)
///////////////
sb.Append(SampleHtml($"<html><head><title>Title</title></head><body><p>this is a sample that how to make html</p></body></html>"$))
/////////////
sb.Append($"</p></body></html>"$)
 
Upvote 0
Top