Debian Codegraph @

tests/data/test_script_string_as_array.kscript

raw
1 function main()
2 array_set_count(my_string, 10);
3 for (my_int, 0, 9, array_set(my_string, my_int, 'b'));
4 { now my_string should be 'bbbbbbbbbb' }
5 my_string := my_string + array_get(my_string, 5) + array_get(my_string, 5) +
6 character_from_code(123);
7 { now my_string should be 'bbbbbbbbbbbb' + #123 }
8 my_string := my_string + string(array_get_count(my_string))
9 { now my_string should be 'bbbbbbbbbbbb' + #123 + '13' }
10
11 function error1()
12 my_string := '';
13 array_set(my_string, 0 { incorrect - index outside string length }, 'b')
14
15 function error2()
16 my_string := 'sdfulwehruhwurhui23h4uioh2uio34';
17 array_set(my_string, 10, 'blah' { incorrect - this must be 1 single character })
18
19 function error3()
20 my_string := '';
21 my_string := array_get('blah', 10 { incorrect - index outside string length })