Atomic types / Char (Character)


Char (Character)

A single alphanumeric character is of type "Char" in JM°.

Create

A char object is created between two single quotes:

'a'

Special and control characters

'\\' Backslash
'\'' Single quote
'"' Double quote
'\n' Line break
'\t' Tab
'\r' Return
'\f' Line feed
'\b' Backspace

Umwandlung

In JM° wird generell sinngemäß umgewandelt, weshalb ein:

'5'.toInt

zur Ganzzahl 5 konvertiert wird. Sollte eine Umwandlung nicht möglich sein, z.B. bei einem Buchstaben, so wird ein Fehler geworfen.

Die Ordinal-Zahl erhalten wir wie folgt:

'a'.ord

Die Umkehrung lautet:

97.chr

Unicode

UTF-8 - characters can be entered as in Java with '\uXXXX'. "XXXX" stands for 2 bytes in hex in this case.

Example:

'\u00ea'.print

At runtime, a character can also be converted to a Unicode string. The inversion is possible as well.

'x'.toUnicode.print			# Ergibt: "\u0078"
"\\u0078".fromUnicode.print	# Ergibt: 'x'

In the second example the second backslash is necessary, otherwise the Unicode character is recognized and translated directly.



- Powered by OghsWiki -

 

 

Sponsor

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

Received:  0 €