Jump to content

H5GG Advance Tutorial - Read UTF16/UTF32 String in JavaScript


3 posts in this topic

Recommended Posts

Updated (edited)

function readUTF16String(address, maxlen)
{
    var str = "";
    for (var s = 0; !maxlen||s<maxlen; s++) {
        var charCode = Number(h5gg.getValue(address + s * 2, "U16"));
        if(!charCode) break;
        str += String.fromCharCode(charCode);
    }
    return str;
}

function readUTF32String(address, maxlen)
{
    var str = "";
    for (var s = 0; !maxlen||s<maxlen; s++) {
        var charCode = Number(h5gg.getValue(address + s * 4, "U32"));
        if(!charCode) break;
        str += String.fromCharCode(charCode);
    }
    return str;
}


//This is usually slower, It is recommended to cache it

//var str1 = readUTF16String(addr);
//var str2 = readUTF16String(addr, 20);
//var str3 = readUTF32String(addr);
//var str4 = readUTF32String(addr, 20);

 

Updated by tuancc
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines