Share via


Small Basic #4: Working with Text

Here is some code demonstrating how to use all of the Microsoft Small Basic Text class's methods:

 TextWindow.Write("What is your first name? ")
firstName = TextWindow.Read()
TextWindow.Write("What is your last name? ")
lastName = TextWindow.Read()
firstNameWithSpace = Text.Append(firstName, " ")
fullName = Text.Append(firstNameWithSpace, lastName)

TextWindow.WriteLine("Your full name is " + fullName + ".")
TextWindow.WriteLine("The lowercase version is " + Text.ConvertToLowerCase(fullName) + ".")
TextWindow.WriteLine("The uppercase version is " + Text.ConvertToUpperCase(fullName) + ".")
TextWindow.WriteLine("Your full name ends with the letter 'e': " + Text.EndsWith(fullName, "e") + ".")
TextWindow.WriteLine("The position of the first letter 'a' in your full name is: " + Text.GetIndexOf(fullName, "a") + ".")
TextWindow.WriteLine("Your full name is " + (Text.GetLength(fullName) - 1) + " characters long.")
TextWindow.WriteLine("The first four characters are: " + Text.GetSubText(fullName, 1, 4) + ".")
TextWindow.WriteLine("The last four characters are: " + Text.GetSubTextToEnd(fullName, Text.GetLength(fullName) - 3) + ".")
TextWindow.WriteLine("Your full name contains the letter 'a': " + Text.IsSubText(fullName, "a") + ".")
TextWindow.WriteLine("Your full name starts with 'P': " + Text.StartsWith(fullName, "P") + ".")
TextWindow.WriteLine("The character for character code 97 is: " + Text.GetCharacter(97) + ".")
TextWindow.WriteLine("The character code for 'a' is: " + Text.GetCharacterCode("a") + ".")

Notice that there are methods for appending, lowercasing, and uppercasing text, as well as several methods for comparing and extracting text. There are also a few methods for converting between characters and character codes.