this code crashes when i click button...
if i remove while block, the String2Hex procedure returns nothing...
what should i do?
Can you please post the full JS code here?
wstring = window.AppInventor.getWebViewString();bytes = new TextEncoder().encode(wstring);result = "";for (let i = 0; i !== bytes.length; i++) {result += ((bytes[i])>>>0).toString(16);}window.AppInventor.setWebViewString(result);
Just to be clear, are you trying to encode a string to hex value?
yeah
Try this.
Script (modified from Javascript: Unicode string to hex - Stack Overflow):
var hex; var result = ""; for (i = 0; i < text.length; i++) { hex = text.charCodeAt(i).toString(16); result += (hex).slice(-4); } window.AppInventor.setWebViewString(result)
AIA:
encode.aia (2.0 KB)
i wanna make the procedure to return the result, not the WebViewStringChanged event changes text :<
I don't think you can, because you need to wait for a moment to return the result (and the nature of App Inventor).
oh....
then is there any way to convert string into hex without using js?
Here you have an extension, but it has the same synchronization problem.
wait, then converting string into hex is possible by making extension?
Here are some blocks you can drag into the Blocks Editor ...
AsciiCHRASCprocedures.aia (4.4 KB)
AsciiCHRASCprocedures.aia (4.4 KB)