B4J Question [BANano] What can be used to replace B4X's CSBuilder

toby

Well-Known Member
Licensed User
Longtime User
I'm porting some code from B4A to B4J BANano and it's not recognized in B4J. Is it as designed or there is something wrong with my installation?
 
Last edited:
Solution
My solution: Use StringBuilder to build text with html tags and assign the text to a SKLabel.

Dim sbDetail As StringBuilder
sbDetail.Initialize
sbDetail.Append($"<p>I am normal</p>"$)
sbDetail.Append($"<p style="color:red;">I am red</p>"$)
sbDetail.Append($"<p style="color:blue;">I am blue</p>"$)
sbDetail.Append($"<p style="font-size:50px;">I am big</p>"$)
SKLabel1.Text=sbDetail
[/CODE]

Alexander Stolte

Expert
Licensed User
Longtime User
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I've updated the subject, it's a B4J BANano pwa project, therefore I can't use any regular B4J view, including BBCodeView. :(
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
My solution: Use StringBuilder to build text with html tags and assign the text to a SKLabel.

Dim sbDetail As StringBuilder
sbDetail.Initialize
sbDetail.Append($"<p>I am normal</p>"$)
sbDetail.Append($"<p style="color:red;">I am red</p>"$)
sbDetail.Append($"<p style="color:blue;">I am blue</p>"$)
sbDetail.Append($"<p style="font-size:50px;">I am big</p>"$)
SKLabel1.Text=sbDetail
[/CODE]
 
Last edited:
Upvote 0
Solution

toby

Well-Known Member
Licensed User
Longtime User
csBuilderReplacement2.png

Other tips
  1. Replace CRLF with "<BR>"
  2. Replace all Pop's and PopAll's with corresponding html closing tags, such as "</div>", "</p>", "</h3>", etc.
 
Last edited:
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
View attachment 133779
Other tips
  1. Replace CRLF with "<BR>"
  2. Replace all Pop's and PopAll's with corresponding html closing tags, such as "</div>", "</p>", "</h3>", etc.
You can also use this:


B4X:
    {B}{/B}: Bold
    {I}{/I}: Italic
    {U}{/U}: Underline
    {SUB}{/SUB}: Subscript
    {SUP}{/SUP}: Superscript
    {BR}: Line break
    {WBR}: Word break opportunity
    {NBSP}: Non breakable space
    {AL}http://...{AT}text{/AL}: Link, opening a new tab
    {AS}http://...{AT}text{/AS}: Link, not opening a new tab
    {C:#RRGGBB}{/C}: Color
    {ST:styles}{/ST}: Add specific styles e.g. {ST:font-size:0.9rem;color:#2B485C}My text in font-size 0.9rem{/ST}
    {IC:#RRGGBB}{/IC}: Icons (if the correct .css or font is loaded) e.g. {IC:#FFFFFF}fa fa-refresh{/IC}
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
The accepted solution works, but this is just because label.text happens to use javascripts .html() method in this case. It should not be considered the general rule. Angel_s solution is definitely the better one for formatting SKLabels, but if you really want to go beyond the basic components, you should read the chapter on BANanoElement in the booklet (chapter 6).

BANanoElement + B4Js SmartStrings are what make BANano so powerful to make WebApps. The best advice I can give is study the booklet.

B4X:
Dim myHTML As String = $"
<p>I am normal</p>
<p style="color:red;">I am red</p>
<p style="color:blue;">I am blue</p>
<p style="font-size:50px;">I am big</p>    
"$
        
Private body As BANanoElement
body.Initialize("body")
    
body.Append(myHTML)

Alwaysbusy
 
Upvote 0
Top