Page 1 of 1

#PB_String_WithZero for StringByteLength()

Posted: Mon Dec 19, 2016 1:25 pm
by Lebostein
In accordance with #PB_String_NoZero for PokeS() and PeekS()

Re: #PB_String_WithZero for StringByteLength()

Posted: Mon Dec 19, 2016 8:50 pm
by Mistrel

Code: Select all

StringByteLength(String.s)+SizeOf(Character)

Re: #PB_String_WithZero for StringByteLength()

Posted: Mon Dec 19, 2016 9:13 pm
by kenmo
I use something like

Code: Select all

Macro StringByteLengthN(String, Format = #PB_Ascii + #PB_Compiler_Unicode)
  (StringByteLength(String, Format) + 1 + Bool(Format = #PB_Unicode))
EndMacro

Debug StringByteLengthN("Hello")
Debug StringByteLengthN("Hello", #PB_Ascii)
Debug StringByteLengthN("Hello", #PB_UTF8)
Debug StringByteLengthN("Hello", #PB_Unicode)
(warning: that Format trick assumes #PB_Unicode = #PB_ASCII + 1)