2024-12-12 16:07:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
fn print(msg: string) #[builtin(Print)] {}
|
2024-12-13 06:09:10 +01:00
|
|
|
fn println(msg: string) { print(msg + "\n") }
|
2024-12-12 16:07:59 +01:00
|
|
|
|
2024-12-13 06:09:10 +01:00
|
|
|
fn string_push_char(str: string, value: int) -> string #[builtin(StringPushChar)] {}
|
2024-12-12 16:07:59 +01:00
|
|
|
fn string_char_at(str: string, index: int) -> int #[builtin(StringCharAt)] {}
|
|
|
|
fn string_length(str: string) -> int #[builtin(StringLength)] {}
|
|
|
|
|
2024-12-13 06:09:10 +01:00
|
|
|
fn array_new_string() -> [string] #[builtin(ArrayNew)] {}
|
|
|
|
fn array_push_string(array: [string], value: string) #[builtin(ArrayPush)] {}
|
|
|
|
fn array_length_string(array: [string]) -> int #[builtin(ArrayLength)] {}
|
|
|
|
fn array_at_string(array: [string], index: int) -> string #[builtin(ArrayAt)] {}
|
2024-12-12 16:07:59 +01:00
|
|
|
|
|
|
|
fn char(ch: string) -> int {
|
|
|
|
string_char_at(ch, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn split(str: string, seperator: int) -> [string] {
|
|
|
|
let result: [string] = array_new_string();
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
let current_str = "";
|
|
|
|
loop {
|
2024-12-13 06:09:10 +01:00
|
|
|
if i >= string_length(str) {
|
|
|
|
break;
|
|
|
|
}
|
2024-12-12 16:07:59 +01:00
|
|
|
let char = string_char_at(str, i);
|
|
|
|
if char == seperator {
|
|
|
|
array_push_string(result, current_str);
|
|
|
|
current_str = "";
|
|
|
|
} else {
|
|
|
|
string_push_char(current_str, char);
|
|
|
|
}
|
|
|
|
i = i + 1;
|
|
|
|
}
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let array = split("aoisfjasoifjsaiofjsa", char("a"));
|
|
|
|
let i = 0;
|
2024-12-13 06:09:10 +01:00
|
|
|
let array_length = array_length_string(array);
|
2024-12-12 16:07:59 +01:00
|
|
|
loop {
|
2024-12-13 06:09:10 +01:00
|
|
|
if i >= array_length {
|
2024-12-12 16:07:59 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-12-13 06:09:10 +01:00
|
|
|
let v = array_at_string(array, 0);
|
|
|
|
println(v);
|
|
|
|
i = i + 1;
|
2024-12-12 16:07:59 +01:00
|
|
|
}
|
|
|
|
}
|