Intro
Strings are for storing text.
Strings are written with double quotes.
Ex
reka x = "Hello World"
String Methods
Kin provides various String manipulation methods, all are provided under KIN_AMAGAMBO
in-built utility.
String concationation
You can concatinate strings by using KIN_AMAGAMBO.huza()
method.
Ex:
reka x = "Hello "
reka y = "World"
reka z = KIN_AMAGAMBO.huza(x, y)
tangaza_amakuru(z)
Output: Hello World
Note:
KIN_AMAGAMBO.huza()
method can take any number of arguments.
String Length
You can get the length of a string by using KIN_AMAGAMBO.ingano()
method.
Ex:
reka ijambo = "Hello World"
tangaza_amakuru(KIN_AMAGAMBO.ingano(ijambo))
Output: 11
Splitting String
You can split a string by using any delimiter by using KIN_AMAGAMBO.tandukanya()
method.
Ex
reka ijambo = "Hello World"
reka hello = KIN_AMAGAMBO.tandukanya(ijambo, " ")
tangaza_amakuru(hello[0])
Output: Hello
Note: This
KIN_AMAGAMBO.tandukanya()
method returns an array, if you try to print it, you'll get this to screen[Object Object]
, this is becuaseArrays
areObjects
in Kin and when ever you try to print the wholeArray
you'll receive[Object Object]
. You have to work with individual element by now!.
Upper Case and Lower Case
- UpperCase
KIN_AMAGAMBO.inyuguti_nkuru(string) # This will turn provided string turned into uppercase
- LowerCase
KIN_AMAGAMBO.inyuguti_ntoya(string) # This will turn provided string turned into lowercase
Getting character
You can get a character at a given index in string by using KIN_AMAGAMBO.inyuguti(string, characterIndex)
method.
Ex:
reka str = "this is a string"
reka char = KIN_AMAGAMBO.inyuguti(8) # this will return a.
tangaza_amakuru(char)
This will print letter
a
to the console.
Iterating over String
In Kin, by the help of KIN_AMAGAMBO.ingano()
and KIN_AMAGAMBO.inyuguti()
methods, it's possible to iterate over a stringify.
Here's how
reka str = "a string"
reka i = 0
subiramo_niba(i<KIN_AMAGAMBO.ingano(str)) { # use KIN_AMAGAMBO.ingano() to get string's length and loop utils the length
tangaza_amakuru(KIN_AMAGAMBO.inyuguti(str, i)) # Get the character at any index by using KIN_AMAGAMBO.inyuguti() method.
i = i + 1
}
Output: every letter printed on it's own line.