It would be nice to add functions like :
- Left(length, text) : extract length characters from text from left
- Mid(start, length, text)
- Right(length, text)
I have written some procedures but can't find equivalent code with functions.
A built in library would be certainly more compact than what I wrote.
Here is the code for those who are interested :
Code: Select all
sub procedure str_left(dim nb_char as byte, dim byref text as string[255], dim byref result_txt as string[255])
dim i as byte
for i = 0 to nb_char - 1
result_txt[i] = text[i]
next i
end sub
sub procedure str_mid(dim start, nb_char as byte, dim byref text as string[255], dim byref result_txt as string[255])
dim i,j as byte
j = start-1
for i = 0 to nb_char - 1
result_txt[i] = text[j+i]
next i
end sub
sub procedure str_right(dim nb_char as byte, dim byref text as string[255], dim byref result_txt as string[255])
dim i,j as byte
j = strlen(text)-nb_char
for i = 0 to nb_char - 1
result_txt[i] = text[j+i]
next i
end sub
dim text1 as string[20]
dim txtresult as string[20]
main:
text1 = "AZERTYUIOPQSDFGHJKLM"
str_left(5,text1,txtresult) 'will return "AZERTY" in txtresult
txtresult = " "
str_mid(7,3,text1,txtresult) 'will retrun "UIO" in txtresult
txtresult = " "
str_right(3,text1,txtresult) ''will retrun "KLM" in txtresult