Is there any way to count the byte size of text without using Binary API ?
@tuyenhx
You could create an component via Integration Studio that tells you this. The following C# code should do the trick;
// Calculate byte size of string in UTF-16int byteSize = Encoding.Unicode.GetByteCount(text);
Hi @tuyenhx ,You can check this Link.Here you can get the file size with the help of JS.Regards,Anubhav
To get the "size" of a text, you can use Length()
This is not true. The byte size of a string/text is possible different then the length.
As ripped from stackoverflow;
Nope. A zero terminated string has one extra byte. A pascal string (the Delphi shortstring) has an extra byte for the length. And unicode strings has more than one byte per character.
By unicode it depends on the encoding. It could be 2 or 4 bytes per character or even a mix of 1,2 and 4 bytes.
Since I can store unicode strings in a Text I presume that we use 2 bytes per character but I could not find any documentation about the real-life implementation of strings in OutSystems. So other then using the TextToBinary action I do not know how to get the byte size. But even then I am not sure if this will truly represent the actual Byte Size because I'm not sure if the extra metadata from the string is removed with this action.
@tuyenhx : Why do you need this?
Both C# and JavaScript use UTF-16. So it's 2 bytes per character for anything but the most outlandish ones (don't know about emojis, those could be 4).
I found this about UTF-16;
In UTF-16, a single character takes either 2 bytes or 4 bytes, depending on whether the character falls within the Basic Multilingual Plane (BMP) or outside the BMP, respectively. Characters within the BMP, such as most commonly used alphabets and symbols, are represented using 2 bytes. Characters outside the BMP, such as emoji and certain uncommon characters, are represented using 4 bytes.
All in all, the Length of a string will surely not tell the byte size of a string.
i am rebuilding an application and it required to count a byte of japanese text, so i'm trying to do it without using API, because asking for permission to use API is quite hard
Would my suggestion below (C# code) be a solution for you?
Vincent Koning is right.
This post shows the difference between software engineers and citizen developers 😊
(With utmost respect for all of them of course)