niva Help

String

For now niva using java.String, so everything about Java strings also applies to niva strings.
For example, immutability and deduplication(small strings are stored once if they are the same, so 10k of "Cat"s strings will take up space as one)

Interpolation of variables is supported(but not for expressions):

x = "Alice" "Hi $x!"

Every niva object has a string representation:

person = Person name: "Alice" age: 24 person toString // Person name: Alice age: 24

Message echo and string interpolation apply the toString method automatically.

unary

Length of this String

count -> Int

Returns a string with characters in reversed order

reversed -> String

Returns a string having leading and trailing whitespace removed

trim -> String

Detects a common minimal indent of all the input lines, removes it from every line

trimIndent -> String

true if this char sequence is empty or consists solely of whitespace characters

isBlank -> Boolean

Only the "" is true

isEmpty -> Boolean

True if its only digits and characters like "abc123"

isAlphaNumeric -> Boolean

Opposite to isBlank

isNotBlank -> Boolean

Opposite to isEmpty

isNotEmpty -> Boolean
toInt -> Int
toFloat -> Float
toDouble -> Double

Returns the first character or panic

first -> Char

Returns the last character or panic

last -> Char
indices -> IntRange
echo -> Unit

binary

Concatenate 2 Strings

+ String -> String
== String -> Boolean
!= String -> Boolean

keyword

"Tom the cat" replace: "cat" with: "mouse"

replace: String with: String -> String

"abc" forEach: [char -> char echo] // a b c

forEach: [Char -> Unit] -> Unit

"abc" forEachIndexed: [index, char -> char echo] // a b c

forEachIndexed: [Int, Char -> Unit] -> Unit

"abc" filter: [it != 'c'] // "ab"

filter: [Char -> Boolean] -> String

"abc" startsWith: "ab" // true

startsWith: String -> Boolean
contains: String -> Boolean

see startWith:

endsWith: String -> Boolean

Returns a substring of this string that starts at the specified startIndex and continues to the end of the string

substring: Int -> String

Returns a string containing characters of the original string at the specified range

"abcd" slice: 0..<3 // abc
slice: IntRange -> String

Returns a substring after the first occurrence of delimiter

substringAfter: String -> String
substringAfterLast: String -> String

see substringAfter:

substringBefore: String -> String
substringBeforeLast: String -> String

see substring:

substringFrom: Int to: Int -> String

Returns the character of this string at the specified index or panic

at: Int -> Char

Returns a string with the first n characters removed "abc" drop: 5 // empty ""

drop: Int -> String

Returns a string with the last n characters removed

dropLast: Int -> String
map: [Char -> T] -> List::T
split: String -> List::String
Last modified: 02 November 2024