I use this C# code to find out how many bytes my string has:
private void CalculateBytes(string text)
{
string s = Convert.ToString(text);
int len = Encoding.UTF8.GetByteCount(s);
}
But I don't know how to do the same thing in javascript. How can I calculate the bytes of my string in javascript?
UPDATE:
TextEncoder() and Buffer are not working. I get an error message:
"Error": { "Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "ReferenceError: Buffer is not defined\n at getBinarySize (BFD0A-main.js:763:5)\n at handlers.GetBytesFromText (BFD0A-main.js:756:24)\n at Object.invokeFunction (Script:116:33)" }
var text = "Text";
var bytes = (new TextEncoder().encode(text)).length;
Buffer.byteLength(text, 'utf8'))
I use Microsoft PlayFab Cloud Script: https://learn.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript/quickstart