@mk-soft
Your ProcedureReturn values should be swapped?
How do I get the leftmost/righmost character in a string?
Re: How do I get the leftmost/righmost character in a string?
@idle
I have already prepared something for your modules
I have already prepared something for your modules
Code: Select all
;-TOP by mk-soft
Procedure IsUTF16String(String$)
Protected *String.Unicode = @String$
If *String
While *String\u
If *String\u > $D7FF And *String\u < $E000
ProcedureReturn #True
EndIf
*String + 2
Wend
EndIf
ProcedureReturn #False
EndProcedure
Procedure LenUTF16(String$)
Protected *Char.Unicode
Protected cnt
*Char.Unicode = @String$
If *Char
While *Char\u
If *Char\u > $D7FF And *Char\u < $E000
*Char + 4
Else
*Char + 2
EndIf
cnt + 1
Wend
EndIf
ProcedureReturn cnt
EndProcedure
Procedure.s LeftUTF16(String$, Length)
Protected *Char.Unicode
Protected len, cnt
If Length < 1
ProcedureReturn ""
EndIf
*Char.Unicode = @String$
If *Char
While *Char\u
If cnt >= Length
Break
EndIf
If *Char\u > $D7FF And *Char\u < $E000
*Char + 4
len + 2
Else
*Char + 2
len + 1
EndIf
cnt + 1
Wend
EndIf
ProcedureReturn Left(String$, len)
EndProcedure
Procedure.s RightUTF16(String$, Length)
Protected *Char.Unicode, *Char2.Unicode, *String.Unicode
Protected len, cnt
If Length < 1
ProcedureReturn ""
EndIf
*String = @String$
If *String
*Char = *String + StringByteLength(String$) - 2
While *Char\u
If cnt >= Length Or *Char <= *String
Break
EndIf
*Char2 = *Char - 2
If *Char2 >= *String And (*Char\u > $D7FF And *Char\u < $E000)
*Char - 4
len + 2
Else
*Char - 2
len + 1
EndIf
cnt + 1
Wend
EndIf
ProcedureReturn Right(String$, len)
EndProcedure
; ****
Define s1.s
s1 = "🅐A🅚K🅝"
Debug "Is '" + s1 + "' UFT16: " + IsUTF16String(s1)
Debug "StringByteLength = " + StringByteLength(s1)
Debug "Len = " + LenUTF16(s1)
Debug "Left = " + LeftUTF16(s1, 2)
Debug "Right = " + RightUTF16(s1, 2)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: How do I get the leftmost/righmost character in a string?
I don't think so, as it is no longer a UCS-2 string
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: How do I get the leftmost/righmost character in a string?
Thanks looks goodmk-soft wrote: Sat May 06, 2023 11:41 am @idle
I have already prepared something for your modulesCode: Select all
;-TOP by mk-soft Procedure IsUTF16String(String$) Protected *String.Unicode = @String$ If *String While *String\u If *String\u > $D7FF And *String\u < $E000 ProcedureReturn #True EndIf *String + 2 Wend EndIf ProcedureReturn #False EndProcedure Procedure LenUTF16(String$) Protected *Char.Unicode Protected cnt *Char.Unicode = @String$ If *Char While *Char\u If *Char\u > $D7FF And *Char\u < $E000 *Char + 4 Else *Char + 2 EndIf cnt + 1 Wend EndIf ProcedureReturn cnt EndProcedure Procedure.s LeftUTF16(String$, Length) Protected *Char.Unicode Protected len, cnt If Length < 1 ProcedureReturn "" EndIf *Char.Unicode = @String$ If *Char While *Char\u If cnt >= Length Break EndIf If *Char\u > $D7FF And *Char\u < $E000 *Char + 4 len + 2 Else *Char + 2 len + 1 EndIf cnt + 1 Wend EndIf ProcedureReturn Left(String$, len) EndProcedure Procedure.s RightUTF16(String$, Length) Protected *Char.Unicode, *Char2.Unicode, *String.Unicode Protected len, cnt If Length < 1 ProcedureReturn "" EndIf *String = @String$ If *String *Char = *String + StringByteLength(String$) - 2 While *Char\u If cnt >= Length Or *Char <= *String Break EndIf *Char2 = *Char - 2 If *Char2 >= *String And (*Char\u > $D7FF And *Char\u < $E000) *Char - 4 len + 2 Else *Char - 2 len + 1 EndIf cnt + 1 Wend EndIf ProcedureReturn Right(String$, len) EndProcedure ; **** Define s1.s s1 = "🅐A🅚K🅝" Debug "Is '" + s1 + "' UFT16: " + IsUTF16String(s1) Debug "StringByteLength = " + StringByteLength(s1) Debug "Len = " + LenUTF16(s1) Debug "Left = " + LeftUTF16(s1, 2) Debug "Right = " + RightUTF16(s1, 2)
Re: How do I get the leftmost/righmost character in a string?
Thank you guys that you invest so much efforts in my problem.
But I do not want to include extra modules and procedures in my code. My goal is to simply test if there is one of these strange characters on the right end of my strings. My strings involved only contain one of these characters each, and I can usethis works in this case.
Alsoworks. And even
work.
Nevertheless it's strange and a pity that it does not work with all PB string functions.
Henry
But I do not want to include extra modules and procedures in my code. My goal is to simply test if there is one of these strange characters on the right end of my strings. My strings involved only contain one of these characters each, and I can use
Code: Select all
If Right(mystring$, 2) = "🅐"
Also
Code: Select all
If FindString(mystring$, "🅐")
Code: Select all
RemoveString(mystring$, "🅚")
ReplaceString(mystring$, "🅚", "nothing")
Nevertheless it's strange and a pity that it does not work with all PB string functions.
Henry
Re: How do I get the leftmost/righmost character in a string?
UTF is too complex ! I stopped my read to Unicode 0xD83C. Now, I suppose the IDE does not support it...
Re: How do I get the leftmost/righmost character in a string?
I already posted some supplementary functions in the german board:
Characters above the Basic Multilingual Plane (BMP) plane
Characters above the Basic Multilingual Plane (BMP) plane
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: How do I get the leftmost/righmost character in a string?
Thank you ! (Die Zeit verbringt...
)
