String methods

Edit

Introduction #

String in a programming language is a sequence of characters. It is used to represent text rather than numbers.
Strings are contained within a pair of double quotes, i.e. "Cat" or "Hello World".
Strings can contain numbers, however you must realize that "5" doesn’t have the value of 5, it has the value of 0, the same as "a" does.
You cannot add strings either, i.e. "12" + "34" isn’t "46", it’s "1234". 12 + 34 is 46.
If you wish to convert a string to a number, you can use Math: String to Real command.


Edit

String: Position #

Returns the position of the first occurrence of a specified value in a string. Case sensitive.
Return 0 if it doesn’t find any match.

Box Name Type Description
Variable String Variable name to save the position
String String String to search
Find String String String to search for
Value to search for String Position returned
“hello” “hello and hello world” 1
“hello” “Hello and hello world” 11
“hello” “Hello and Hello world” 0


Edit

String: Length #

Returns the length of a string.

Box Name Type Description
Variable String Variable name.
String Variable String Variable name containing the string.
String Length returned
“Hello” 5
”” 0


Edit

String: Clamp #

Extracts a part of a string and returns the extracted part.
You need to specify the index of the first character and the amount of characters to extract.

Box Name Type Description
Variable String Variable name containing the string to clamp
Start Real Where to start the clamp
Count Real Amount of characters to include in the clamp
Original string Start Count Result
“Hello World!” 0 5 “Hello”
“This is cool!” 9 4 “cool”


Edit

String: Count #

Returns the number of occurrences of a character/string within a string. Case sensitive.

Box Name Type Description
Variable String Variable name.
String Variable String Variable name containing the string.
Value to search for String Result
“Ab” “AbAbAbAb” 4
“33” “333 and 33 and 33333” 7
“black” “Mr.Black has a black car and a black cat.” 2


Edit

String: Replace #

Searches a string for a specified value and returns a new string where all the occurrences of the specified value are replaced. Case sensitive.

Box Name Type Description
Variable String Variable name containing the original string.
Replace String Value that will be replaced by the new value.
New String String The value to replace the search value with. Can be empty to completely remove it.
Value to search for Value to replace it with String Result
“l” ”/” “Hello” “He//o”
” “ ”-“ “Hello World” “Hello-World”
“black” “white” “Mr.Black has a black car and a black cat.” “Mr.Black has a white car and a white cat.”


Edit

String: Lower Case #

Converts a string to lowercase letters.

Box Name Type Description
Variable String Variable name containing a string to convert to lowercase letters
Original String Returned String
“HELLO World” “hello world”


Edit

String: Upper Case #

Converts a string to uppercase letters.

Box Name Type Description
Variable String Variable name containing a string to convert to uppercase letters
Original String Returned String
“hello world” “HELLO WORLD”


Edit

String: Letters #

Box Name Type Description
Variable String Variable name containing the string you wish to convert to a letter only string
Original String Returned String  
“12.50 USD”   “USD”.
“Hello world!” “Helloworld”  


Edit

Math: String to Real #

Turns a string value into a real value (number).

  • returns 0 if the string does not start with a number or .
  • stops the conversion if it encounters any non number in the string and returns the current converted value
  • converting a value that’s already real returns 0
  • removes any leading zeroes and rounds the number to 2 decimal points
  • string X beginning with a . will be converted to 0.X
  • accepts strings containing Euler’s number
Box Name Type Description
Variable String Name of a variable to save the real value.
String Variable String Name of a variable containing the string to convert.
String Variable value Returned real value
“Hello World” 0
“Hello World 123” 0
“123 Hello World” 123
“123 Hello World 456” 123
“.99” 0.99
“1.239999” 1.24
“000010” 10
“10e-2” 0,10
“10e+2” 1000
10 0


Edit

String: Digits #

Removes all letters and special symbols from a string.

Box Name Type Description
Variable String Variable name.
String Variable String Variable name containing the string.
Original String Processed String
“Hello” ””
“1a2b3c” “123”
“$12.50” “12.50”


Edit

String: Format #

Divides a string into multiple lines. The new line will be compensated with \n.
Very useful command to use together with Math: Trigger Pull for Bits or Redeem points with a message. You can force the viewer’s message to be split into multiple lines in your Text GDI+ source.

Box Name Type Description
Variable String Variable name to save the formatted string
String String String to format. Use /$variable$/ if your string is inside another variable.
Max Width String An arbitrary number. This is technically a pixel width, but you will have to test to see what you receive back.
Max Word Length* String Amount of characters to allow before cutting the word in the middle.


Edit

String: Escape #

Encodes a string, ready to be used in JSON format.
It’s a good practice to escape any viewer entered strings to prevent any possible exploits if you’re sending them to extensions or OBS websocket (like changing GDI+ Text).

Box Name Type Description
Variable String Variable name containing the string you wish to escape.