Skip to main content

String

A string in LemonScript is a set of characters grouped together. You can create a string with an opening and closing " or '. For example 'Hello' or "Bob's hat". This document will be describing a string's static properties and methods.

Note: indices in LemonScript start from 0, so the first character of a string will have index 0, and the second 1, etc

Static Properties#

  • length - The length property describes how many characters are in the string. For example, "hello".length is 5.

Methods#

  • lower() - The lower method returns the string with all lowercase characters. For example, "Hello".lower() is "hello".

  • upper() - The upper method returns the string with all uppercase characters. For example, "hello".upper() is "HELLO".

  • get(index) - The get method returns the character at the given index. For example, "hello".get(0) is "h", and "hello".get(4) is "o". You can also use negative indices to get characters starting from the end of the string. For example, "hello".get(-1) is "o".

  • trim(<character>) - The trim method returns the string with all leading and trailing whitespace removed. If a character is specified, it will remove all leading and trailing chracters that match the character. For example, " hello ".trim() is "hello", and "....hmm..".trim(".") is "hmm".

  • index(text) - The index method returns the index of the first occurrence of the specified text. If no index is found, it returns null. For example, "hello world".index("hello") is 0, and "hello world".index("t") is null.

  • number() - The number method returns a number that was represented in the string. If there is no such number or the string is invalid, it returns null. For example "15".number() returns 15, "-12.2".number() returns -12.2, and "hello".number() returns null.

  • replace(text, replacement) - The replace method replaces all occurrences of the specified text with the specified replacement. For example, "hello world".replace("hello", "hi") is "hi world".

  • slice(min, <max>) - The slice method returns a substring of the string. The min value is the starting index for the chopped string (inclusive), and the max index is the ending index for the substring string (exclusive). If no max index is specified, the substring will be from the min index to the end of the string. For example, "hello world".slice(0, 5) is "hello", and "hello world".slice(6) is "world". You can also use negative indices for the min and max values. A negative index will start from the end of the string. For example, "hello world".slice(-5) is "world", and "hello world".slice(-10, -2) is "ello wor".