Wish Smart string formatters

stevel05

Expert
Licensed User
It would be nice if we could have 2 more smart string formatters namely:
  • Hex to display a value as Hex with a parameter for the output length.
  • BBcode for use with the BCText engine that allows the use of square brackets in text.
 

stevel05

Expert
Licensed User
It's not perfect, but this is what I am currently using. It stops it crashing if you are using unknown text:
B4X:
Private Sub ParseSquareBrackets(Text As String) As String
    Dim Level As Int
    Dim SB As StringBuilder
    SB.Initialize
    For i = 0 To Text.Length - 1
        Dim ch As Char = Text.CharAt(i)
        If ch = "["  Then
            Level = Level + 1
            If Level = 1 Then
                SB.Append("[Plain][")
            Else
                SB.Append("[")
            End If
        Else If ch = "]" Then
            Level = Level -1
            If Level = 0 Then
                SB.Append("][/Plain]")
            Else
                SB.Append("]")
            End If
            Level = Max(Level,0)
        Else
            SB.Append(ch)
        End If
    Next

    If Level > 0 Then SB.Append(" [/Plain]")
    Return SB.ToString
End Sub
 

Attachments

Last edited:
Top