Microsoft Small Basic

Program Listing: JQR856
' Sample Code for Text Object

Init()

' Append and length
txt1 = "Small "
txt2 = "Basic"
txt = Text.Append(txt1, txt2)
msg = "Append: " + txt
ShowMsg() ' Append: Small Basic

len = Text.GetLength(txt)
msg = "Lenght: " + len
ShowMsg() ' Lenght: 11

' Case conversion
txtL = Text.ConvertToLowerCase(txt)
msg = "Lower: " + txtL
ShowMsg() ' Lower: small basic

txt = "αβγ"
txtU = Text.ConvertToUpperCase(txt)
msg = "Upper: " + txtU
ShowMsg() ' Upper: ΑΒΓ

' Sub-texts
txt = "Rectangle"
subTxt = "angle"
If Text.IsSubText(txt, subTxt) Then
msg = subTxt + " is a sub-text of " + txt + "."
Else
msg = subTxt + " isn't a sub-text of " + txt + "."
EndIf
ShowMsg() ' angle is a sub-text of Rectangle.

If Text.EndsWith(txt, subTxt) Then
msg = txt + " ends with " + subTxt + "."
Else
msg = txt + " doesn't end with " + subTxt + "."
EndIf
ShowMsg() ' Rectangle ends with angle.

If Text.StartsWith(txt, subTxt) Then
msg = txt + " starts with " + subTxt + "."
Else
msg = txt + " doesn't start with " + subTxt + "."
EndIf
ShowMsg() ' Rectangle doesn't start with angle.

pos = Text.GetIndexOf(txt, subTxt)
msg = "Index: " + pos
ShowMsg() ' Index: 5

len = 2
subTxt = Text.GetSubText(txt, pos, len)
msg = "Sub-text: " + subTxt
ShowMsg() ' Sub-text: an

subTxt = Text.GetSubTextToEnd(txt, pos)
msg = "Sub-text: " + subTxt
ShowMsg() ' Sub-text: angle

' Character codes
code = 34
char = Text.GetCharacter(code)
msg = "Character: " + char
ShowMsg() ' Character: "

code = Text.GetCharacterCode(char)
msg = "Code: " + code
ShowMsg() ' Code: 34

Sub Init
GraphicsWindow.Title = "Results of Sample Code for Text Operations"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.BackgroundColor = "LightGray"
tbox = Controls.AddMultiLineTextBox(10, 10)
Controls.SetSize(tbox, gw - 20, gh - 20)
EndSub

Sub ShowMsg
buf = buf + msg + CRLF
Controls.SetTextBoxText(tbox, buf)
EndSub