LeftUTF8(String, Pos)
Posted: Sat May 21, 2005 6:41 pm
Code updated For 5.20+
Return UTF-8 Strings
TX
Code: Select all
Procedure.s LeftUTF8(Utf8.s, Utf8_index.b)
Utf8_result.s="" : Utf8_Total.b=1
Utf8_len=Len(Utf8)
For Utf8_pos=1 To Utf8_len
If Asc(Mid(Utf8, Utf8_pos, 1))<$80
If Utf8_index=>Utf8_Total
Utf8_result+Mid(Utf8, Utf8_pos, 1)
Utf8_Total+1
EndIf
ElseIf Asc(Mid(Utf8, Utf8_pos, 1))>$C1 And Asc(Mid(Utf8, Utf8_pos, 1))<$E0
If Utf8_index=>(Utf8_Total+1)
Utf8_result+Mid(Utf8, Utf8_pos, 2)
Utf8_pos+1
Utf8_Total+2
EndIf
ElseIf Asc(Mid(Utf8, Utf8_pos, 1))>$DF And Asc(Mid(Utf8, Utf8_pos, 1))<$F0
If Utf8_index=>(Utf8_Total+1)
Utf8_result+Mid(Utf8, Utf8_pos, 3)
Utf8_pos+2
Utf8_Total+2
EndIf
Else
If Utf8_index=>(Utf8_Total+1)
Utf8_result+Mid(Utf8, Utf8_pos, 4)
Utf8_pos+3
Utf8_Total+2
EndIf
EndIf
Next
ProcedureReturn Utf8_result
EndProcedure
TX