string.eh
String operations. More...
Functions
Description
String is a sequence of unicode characters. Every character is a number in
range 0..65535. Strings are immutable, once created string cannot change.
If you need changeable strings, use either
StrBuf or
CArray.
Starting from release 2.0, you can use square brackets []
to get
individual character or substring:
Function details
Returns string representation of the value.
If value is:
-
String
- value itself is returned;
-
Int
, Long
, Float
or Double
- string
representation as a decimal number is returned;
-
StrBuf
- new string allocated with characters currently contained
in the buffer;
-
Function
- the name of the function is returned;
-
Array
- the string containing all array elements, separated by commas is returned;
-
null
- function returns string "null"
.
It is safe to call this function for values of other types but returned
values are platform dependant and you should not rely on them.
Returns string representing this
Int
as an unsigned binary number.
Returns string representing this
Int
as an unsigned octal number.
Returns string representing this
Int
as an unsigned hexadecimal number.
Returns string representing this
Int
as a signed number in the given base.
Argument
base should be in range 2..36.
Returns string representing this
Long
as a signed number in the given base.
Argument
base should be in range 2..36.
Parses this string as a signed decimal integer.
If string is not representing valid number, then
null
is returned.
def String.tointbase(base: Int): Int;
|
Parses this string as a signed integer in the given base.
Argument @emph base should be in range 2..36.
def String.tolong(): Long;
|
Parses this string as a signed decimal long integer.
If string is not representing valid number, then
null
is returned.
def String.tolongbase(base: Int): Long;
|
Parses this string as a signed long integer in the given base.
Argument
base should be in range 2..36.
def String.tofloat(): Float;
|
Parses this string as a single precision floating point number.
If string is not representing valid number, then
null
is returned.
def String.todouble(): Double;
|
Parses this string as a double precision floating point number.
If string is not representing valid number, then
null
is returned.
Returns length of the string.
Returns character at given position in the string.
You may also use square brackets, as with array.
def String.indexof(ch: Int): Int;
|
Returns index of the first occurence of given character in the string.
If string does not contain given character then -1 is returned.
def String.lindexof(ch: Int): Int;
|
Returns index of the last occurence of given character in the string.
If string does not contain given character then -1 is returned.
Returns index of the first occurence of given substring in the string.
If string does not contain given substring then -1 is returned.
Returns substring of the string.
Returned substring contains all characters in range
from..to-1
.
Returns string with all characters converted to the upper case.
Returns string with all characters converted to the lower case.
Concatenates this string with another string.
The same is done by operator '+'.
Compares this string with another string lexicographically.
Returns zero if two strings are equal, value less than zero if this string
is less than argument and value greater than zero if this string is greater
than argument.
Removes all whitespaces from the beginning and the end of the stream.
This includes removing of
' '
,
'\t'
,
'\r'
and
'\n'
.
Splits the string around given character.
Examples:
"foo,and,baaz".split(',')
"foo,and,baaz".split('a')
|
Returns formatted string using this string as format specification and given arguments.
Format specifiers are substrings of the form
%n
where
n
is from
0 to 9. Each format specifier is substituted with corresponding value from
array
args. Specifier
%%
is substituted with percent character.
For example:
"The price of %0 has decreased by %1%%".format(["cookies", 8])
|
Returns characters of this string as character array.
def String.utfbytes(): BArray;
|
Encodes this string in modified UTF-8 format and returns it as byte array.
Computes 32-bit hash of this string using default Java hashing algorithm.
Creates new string with characters given from specified character array.
Decodes byte sequence as string in modified UTF-8 format.
Returns string containing single character.