Skip to content

String

  • A String is a sequence of characters or symbols with a dynamic length.

Arithmetic

Operator Description
+ Concatenation

Info

  • Concatenation is the merging of two or more Strings to produce a larger combined String.

  • Number can be added to String to produce a new String:

    1 + " Malaysia" is equal to "1 Malaysia"


Logical comparisons

Operator Description
== Equal to
!= Not equal to

Info

Logical comparisons return a Boolean.

Warning

  • String cannot be logically compared with Number. We will need to convert the String to Number or vice versa.

  • Ordered comparisons such as > or < do not work for String. For length comparisons, use the length() function to get the String's length which can then be compared numerically.

Example

1
2
3
4
5
println "abc" == "def"; // false
println "abc" == "abc"; // true
println "abc" + "def";  // "abcdef"
println "abc" + 123;    // "abc123"
println  "abc" - "def"; // Error because Strings cannot be subtracted

Built-in functions

length

length(String)Number

  • Returns the String's length.

to_number

to_number(String)Number

1
println to_number("3.142"); // 3.142

Warning

  • String must be a valid integer or floating point number. Otherwise, the program halts with this error:

Placeholder


split

split(source: String, delimiter: String)Array[String]

Example

1
2
println split("hey, there, whatchu, doing", ",");
// ["hey", "there", "whatchu", "doing"]

insert

insert(source: String, index: Number, new_value: String)Array[String]

1
println insert("arna", 2, "ia"); // "ariana"
  • index must be a positive integer and within the length of the array.

  • Otherwise, the program halts with either of these errors:

Placeholder

Placeholder


remove

remove(source: String, index: Number)String

  • Removes a character specified by the index from the source and returns the result
1
println remove("ariana", 2); // "arana"
  • index must be a positive integer and within the length of the array.

  • Otherwise, the program halts with either of these errors:

Placeholder

Placeholder


to_lowercase

to_lowercase(String)String

  • Returns a lowercased version of the input String

to_uppercase

to_uppercase(String)String

  • Returns a uppercased version of the input String