Strings
A string is a sequence of characters, its an immutable data type in Pa, They can be created using double quotes or single quotes.
Concatenation
Concatenation between strings is done by the + operator, its the only operator that allows either 2 strings or numbers operand types.
//Hello fellow, reader!
"Hello fellow, " + "reader!";
Indexing
You can access a single character by index in a string like so
"Wow"[0]; //W
"Wow"[1]; //o
"Wow"[2]; //W
let wow = "Wow";
wow[0]; //W
Methods
All the current methods of a string object.
length()
Returns the length of the given string.
"wow".length(); //3
toNumber()
Return a casted number from the given string.
"1".toNumber(); //1
"a".toNumber(); //error
split(delimiter: string)
Returns a list of sub-strings, it splits a string by the given delimiter.
//["wow", "wow"]
"wow;wow".split(";");
//["Code", "Clean"]
"CodeisClean".split("is");
lower()
Returns the lowercase version of the given string.
"COOL".lower(); //cool
upper()
Returns the uppercase version of the given string.
"cool".upper(); //COOL
capitalize()
Returns a version of the given string with its first character capitalized.
"cool".capitalize(); //Cool
startsWith(prefix: string)
Returns true if the given string starts with the given prefix. Otherwise false.
"cool".startsWith("c"); //true
"cool".startsWith("co"); //true
endsWith(suffix: string)
Returns true if the given string ends with the given suffix. Otherwise false.
"cool".endsWith("l"); //true
"cool".endsWith("ol"); //true
"cool".endsWith("ool"); //true
isAlpha()
Returns true if the given string's characters are all alphabetic and the string is not empty. Otherwise false.
"wow".isAlpha(); //true
"wow1".isAlpha(); //false
"".isAlpha(); //false
isDigit()
Returns true if the given string's characters are all digits and the string is not empty. Otherwise false.
"wow1".isDigit(); //false
"".isDigit(); //false
"12345".isDigit(); //true
isSpace()
Returns true if the given string's characters are all whitespaces and the string is not empty. Otherwise false.
"w ".isSpace(); //false
"".isSpace(); //false
" ".isSpace(); //true
trimSpace()
Returns a version of the given string with leading and trailing space characters removed.
"w ".trimSpace(); //w
" w ".trimSpace(); //w
"s p a c e".trimSpace(); //space
replace(target: string, new: string)
Replaces the target sub-string with the new given string.
"apple".replace("a", "b"); // bpple
// good and good
"bad and bad".replace("bad", "good");
format(template: string, arguments: any)
Replaces the placeholders inside the template string argument with the given argument values.
"Pa is {}!".format("awesome");
// Pa is awesome
"{} + {}".format(1, 1);
// 1 + 1