This topic provides code samples of how to manipulate strings.
-
Sets the value of a string
myString = "Thank God It's Monday"
-
Gets a specific character within a string and returns a
mySpecialChar = myString(2)
-
Gets the start index of the string and returns 6
myIndex = myString.IndexOf("God")
-
Gets a substring by specifying start index and length and returns God
mySubstring = myString.Substring(6, 3)
-
Replaces the first input parameter with the second and returns Thank God It's Friday
myReplacedString = myString.Replace("Monday", "Friday")
-
Removes whitespace at the beginning and end of a string
myTrimmedString = myString.Trim()
-
Changes all characters to lowercase and returns thank god it's Monday
myStringLowerCase = myString.ToLower()
-
Changes all characters to uppercase and returns THANK GOD IT'S MONDAY
myStringUpperCase = myString.ToUpper()
-
Escapes double quotes by using duplicate double quotes
"Eric said: ""That's a great car!"""