Strings

Introduction

Strings are a sequence of characters enclosed in either single quotes (''), double quotes (""), or backticks (````). Single quotes and double quotes are working the same way, but backticks (string templates) have some special features.

Creating Strings

To create a string, simply enclose a sequence of characters in single or double quotes.ย For example:

let str1 = โ€˜Hello, world!โ€™;
let str2 = โ€œMagiScript is awesome!โ€;

MagiScript also supports template strings, which are enclosed in backticks (```) instead of single or double quotes. Template strings allow multiple lines and also embed expressions inside a string using placeholders. Placeholder expressions are enclosed inย ${}`.ย For example:

_CODE_BLOCK2

String Methods

Below are the String Methods:

strLen

strLenย is a built-in function in MagiScript that returns the length of a string. It takes one argument, which is the string to be measured.ย For example:

_CODE_BLOCK3

strSub

strSubย is a built-in function in MagiScript that extracts a substring from a string. It takes two arguments: the string from which the substring will be extracted, and the starting index (inclusive) and the ending index (exclusive) of the substring. For example:

_CODE_BLOCK4

strCharAt

strCharAtย is a built-in function in MagiScript that returns the character at a specified index in a string. It takes two arguments: the string from which the character will be extracted, and the index of the character.ย For example:

_CODE_BLOCK5

strSplit

strSplit is a built-in function in MagiScript that splits a string into an array of substrings. It takes two arguments: the string to be split, and the separator character or substring. For example:

_CODE_BLOCK6

Conclusion

In MagiScript, strings are a fundamental data type that can be created using single or double quotes or backticks for template strings. While MagiScript doesnโ€™t support the length property of strings, and accessing the letter at an index using brackets (str[2]), we have strLen, strSub, strCharAt and strSplit to help manipulate and extract information from strings.