Android Question string to UTF16 = PHP?

Tayfur

Well-Known Member
Licensed User
Longtime User
I have some codes with PHP;


PHP:
function _UTF8toUTF16($s)
{
    // UTF-8 to UTF-16BE with BOM
    $res = "\xFE\xFF";
    $nb = strlen($s);
    $i = 0;
    while($i<$nb)
    {
        $c1 = ord($s[$i++]);
        if($c1>=224)
        {
            // 3-byte character
            $c2 = ord($s[$i++]);
            $c3 = ord($s[$i++]);
            $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2));
            $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F));
        }
        elseif($c1>=192)
        {
            // 2-byte character
            $c2 = ord($s[$i++]);
            $res .= chr(($c1 & 0x1C)>>2);
            $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F));
        }
        else
        {
            // Single-byte character
            $res .= "\0".chr($c1);
        }
    }
    return $res;
}

I serched an convert PHP code . And My B4a code is:
Code:
Sub UTF8toUTF16(data As String) As String
    Dim bb() As Byte
    bb=data.GetBytes("UTF16")
    Return BytesToString(bb,0,bb.Length,"UTF16")
End Sub


My questions is myB4A code return same PHP return data??
 
Your B4A code doesn't do anything useful.
String variables do not have any encoding.

Encoding is only relevant when you want to convert a string object to bytes or from bytes to a string object.

Thank you for feedback @Erel

how can I do ? some code please.
 
Upvote 0
Back
Top