Atomic types / String (Str)


String (Str)

A string, also called string, is of type "Str" in JM°. This type is relatively identical to a Java string.

Create

A string is created inside quotes:

"abcde123 %ABC_"

... and may of course also be empty:

""

Sequence

Since a string is a list of single characters, so to speak, a string provides many list functions.

s = "abcdef"
s.first.print
s.last.print
s.get(3).print

Hier werden das Erste, das Letzte und das Dritte Zeichen ausgegeben.

Get, Pull

With "get" a single character can be read:

s.get( 3 ).print
s[3].print

Ebenso funktioniert die "lazy"-Variange "pull". Hier wird ggf. kein Fehler geworfen, sondern "nil" zurückgegeben:

s.pull( 9 ).print
s[9]?.print

Das 9. Zeichen existiert nicht, weshalb "nil" zurückgegeben wird.

Set, Put

Also, a string can be modified with "set" and "put" like a list.

Important|Because a string is atomic, a new string is created each time!

With "set" a character can be exchanged.

s.set( 'x', 3 ).print
( s[3] = 'x' ).print

"put" extends the string if necessary, so that the character can be placed in the appropriate position:

s.put( 'x', 9 ).print
( s[9]? = 'x' ).print

Special cases

To insert a quote inside the string, it is preceded by a backslash '\':

"abc\"def\"ghi"

Special characters like newline ('\n') or tab ('\t') can also be inserted:

"abc\ndef\tghi"

Ein Backslash wird wie folgt eingefügt:

"abc\\def"

Unicode character

Unicode characters can also be inserted into a string. The backslash is also used for this, followed by a lowercase 'u' and 4 hexadecimal numbers (0-f).

"abc\u2202def".print

Die Zeichenfolge "\u2202" wird somit ersetzt durch ein: ∂



- Powered by OghsWiki -

 

 

Sponsor

The development of "JayMo" is currently only possible through personal initiative.

Received:  0 €