B4J Question How to split a line of BB-code in editor into multiple parts?

BlueVision

Active Member
Licensed User
Longtime User
How do you define a problem correctly so that you can find the answer in the forum? In that case, I give up and just ask the question again. I have a luxury problem writing code and I just can't find the right answer in the forum. I'm sure someone has answered a similar problem before. As I said, how do you have to phrase the question to get a hit...? It might also be kind of too early in the day to write code....

The problem:
In the editor I write the text for BB-code. Because of the many control characters in the code, one quickly reaches the end of the visible line. Because of the constant horizontal scrolling in the editor, I quickly lose the overview. Which "line connector" can I use in this case to continue the line of code in the next line without horizontal scrolling in the editor?
The variant with an underline ( _ ) at the end of the current line and an ampersand ( & ) at the beginning of the next line does not work in this case.
 

stevel05

Expert
Licensed User
Longtime User
I have played with this as well. Looking at how the code is parsed, I am pretty sure that there is no continuation character.

If you are using a TextArea to edit the code, turn on WordWrap.
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
I have played with this as well. Looking at how the code is parsed, I am pretty sure that there is no continuation character.

If you are using a TextArea to edit the code, turn on WordWrap.
Thank you for your quick reply. As I said, it is a luxury problem.

It is only a simple problem of clarity during writing the "hardwired" text within the editor and looks ugly within the code. The text is fixed and does not change, it is only used for a more detailed explanation.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
It crossed my mind that it would be useful to be able to add comments to the bbcode text, but haven't got around to adding a wish yet.

Until your wish comes true, you can perhaps apply this method ????

Be smart, use smart strings!:
Dim Part1, Part2, Part3 As String
Part1 = $"[Alignment=Center][TextSize=20][b][u]This is the title "$    '--- title text
Part2 = $"$[FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]"$    ' --- Other text font
Part3 = $"Emoji made of multiple "characters": ?‍? And a flag: [TextSize=30][e=??/][/TextSize]"$  ' --- Let show emoji
CodeView1.Text = $"${Part1}${Part2}${Part3}"$    ' --- And combine to one-liner

:p Sorry, I'm in a bit of a corny mood
 
Upvote 0

BlueVision

Active Member
Licensed User
Longtime User
A possible way, combining multiple string into another.

This reminds me of the blessed days of a BASIC interpreter and the "line numbers" before each line. With each CRLF, a number 10 higher was automatically written at the first position of the new line, the interpreter then processed the commands sequentially in the order of these line numbers. The spacing of 10 was intended to be able to insert lines as well, since there were theoretically 9 placeholders in between. If this was no longer sufficient, one could bring the lines of code back to 10 spacing with >RENUMBER<.

We now absolutely need a >RENUMBER< again for this purpose for renaming the "parts" ... o_O

But the approach is good. I already do something similar by "adding" the string line by line... The problem is simply that a lot of space is then lost again for the "string addition".
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
But the approach is good. I already do something similar by "adding" the string line by line... The problem is simply that a lot of space is then lost again for the "string addition".
Unless the entire text is static, I combine dynamic program-generated text into a more descriptive variable name that also allows me to omit the comments. But indeed convenience comes at a price in terms of memory usage.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I use a variable and when the line gets too long I close it and start again.
B4X:
Program = $"[TextSize=18]${CRLF}${B4JCRLF}[/TextSize][Alignment=Center][url]${GetAppTS} .....
${TS}[b]${B4JCRLF}${DCCodeMod.FormFtrClrStr}Blah Blah Blah 1[/color][/b][/TextSize]"$
        Program = $"${Program}
${TS2}Copyright ©${DateTime.GetYear(DateTime.Now)} Blah Blah..."$
#If not(B4J)
        If SC < 6 Then
            Program = $"${CRLF}${Program}"$
        End If
#End If
AboutCV.Text = Program
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
And combining #5 and #8 you can also have comments.

B4X:
    Dim content As String
    content = $"${content}[Alignment=Center][TextSize=20][b][u]This is the title "$        '--- title text
    content = $"${content}[FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]"$        '--- Other text font
    content = $"${content}Emoji made of multiple "characters": ?‍? And a flag: [TextSize=30][e=??/][/TextSize]"$        '--- Let show emoji
    Log(content)

or this, what I prefer, since it is more obvious

B4X:
    Dim content As StringBuilder: content.Initialize
    content.Append($"[Alignment=Center][TextSize=20][b][u]This is the title "$)        '--- title text
    content.Append($"[FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]"$)        '--- Other text font
    content.Append($"Emoji made of multiple "characters": ?‍? And a flag: [TextSize=30][e=??/][/TextSize]"$)        '--- Let show emoji
    Log(content.toString)
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
And Thinking about it probably the cleanest way is to restart on new lines:
B4X:
Dim P as string
P = $"klajshf aer;oh aer;oi aew;foi  oijaef[iaer[ifo  oijaewferg  aerfaef.
"$
P = $"${P};iojare a;ioer ea;oiaeroijalk.areergerh;lkjsd...af

"$
P = $"${P}Etc. Etc.....
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Why not just
B4X:
    Dim s As String
    s = "jjhjhkjjhkjhkjhkjhkjhkjhkjhkjhkjhkjhkjhkjhkhkjhkj" & _
    "iuoiuoiuiuoiuoioiuoiuoiuoiuoiuoiuoiuoiuoiuoiuoiuoiuoi" & _
    "vbvbvbvbvbvbvbvbvbvbvbvbvbbvbvbvbvbvbbvbvbvbvbvbvbbvv"
   
    Log(s)

Works with $"..."$ too
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I believe @Daestrum wins this one - although concatenation is less efficient than .Append :)
B4X:
    Dim content As String = _
    $"[Alignment=Center][TextSize=20][b][u]This is the title "$ & _                                 '--- title text
    $"[FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]"$ & _              '--- Other text font
    $"Emoji made of multiple "characters": ?‍? And a flag: [TextSize=30][e=??/][/TextSize]"$        '--- Let show emoji
    Log(content)
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Why not just
B4X:
    Dim s As String
    s = "jjhjhkjjhkjhkjhkjhkjhkjhkjhkjhkjhkjhkjhkjhkhkjhkj" & _
    "iuoiuoiuiuoiuoioiuoiuoiuoiuoiuoiuoiuoiuoiuoiuoiuoiuoi" & _
    "vbvbvbvbvbvbvbvbvbvbvbvbvbbvbvbvbvbvbbvbvbvbvbvbvbbvv"
 
    Log(s)

Works with $"..."$ too
I don't believe your code will put in any carriage returns. What you have is all on one line. Mine will be on 4 lines (one blank) Also, @Erel thinks using string literals ($""$) is extremely important. I don't understand why but he is a lot smarter than me at this stuff so I will run with it.?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I don't believe your code will put in any carriage returns

How about adding ${CRLF} or to show the paragraphs more clearly:

B4X:
    Dim content As String = _
    $"[Alignment=Center][TextSize=20][b][u]This is the title "$ & _                                 '--- title text
    $"[FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]"$ & _              '--- Other text font
    $"
"$ & _
    $"Emoji made of multiple "characters": ?‍? And a flag: [TextSize=30][e=??/][/TextSize]"$        '--- Let show emoji
    Log(content)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I thought that was the original problem, because the line didn't have CRLF it appeared on one loooong line in the editor, which is hard to read without horizontal scrolling.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
How about adding ${CRLF} or to show the paragraphs more clearly:

B4X:
    Dim content As String = _
    $"[Alignment=Center][TextSize=20][b][u]This is the title "$ & _                                 '--- title text
    $"[FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]"$ & _              '--- Other text font
    $"
"$ & _
    $"Emoji made of multiple "characters": ?‍? And a flag: [TextSize=30][e=??/][/TextSize]"$        '--- Let show emoji
    Log(content)
In your example the
B4X:
"$ & _  
    $"
are unnecessary simpler to leave them out.
 
Upvote 0
Top