Get the size of a string in bytes

darbid

Registered User.
Local time
Today, 15:19
Joined
Jun 26, 2008
Messages
1,428
The title says it all.

I need to test that a string is not bigger than 262064 bytes. How would one do that.
 
Because of Unicode the LenB() function may be a better choice as in: -

LenB(MyString)

Hope that helps.

Regards,
Chris.
 
Hi -

That's very interesting. Never saw that demonstrated before.

Code:
x = "I need to test that a string is not bigger than 262064 bytes. How would one do that."

? len(trim(x))
 84 
 
? lenb(trim(x))
 168

Thanks for that - Bob
 
Yes, Len() is suitable for stepping through characters in a string but in Unicode a character is two bytes.
So, with Unicode, the number of bytes is twice the number of characters.

It’s probably more complicated than that but will do for the moment.

Regards,
Chris.
 
Thank you guys. G-T-H I was worried about your answer cause I was thinking about the whole Unicode and VBA as I recently had to get my program to read Unicode text files which is very different to reading ASCII ones.

I actually came accross the "B"'S last night and wanted to post but did not till now. Thanks Chris for getting it for me. I will test it and write back.
 

Users who are viewing this thread

Back
Top Bottom