Tayfur Well-Known Member Licensed User Longtime User Feb 15, 2016 #1 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: B4X: 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??
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: B4X: 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??
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2016 #2 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. Upvote 0
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.
Tayfur Well-Known Member Licensed User Longtime User Feb 16, 2016 #3 Erel said: 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. Click to expand... Thank you for feedback @Erel how can I do ? some code please. Upvote 0
Erel said: 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. Click to expand... Thank you for feedback @Erel how can I do ? some code please.
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2016 #4 What do you need to do? What is the input and what is the output? Upvote 0
Tayfur Well-Known Member Licensed User Longtime User Feb 16, 2016 #5 Erel said: What do you need to do? What is the input and what is the output? Click to expand... output values for special file format. after I wirete directly a file. (I have only php code) Upvote 0
Erel said: What do you need to do? What is the input and what is the output? Click to expand... output values for special file format. after I wirete directly a file. (I have only php code)
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2016 #6 You can use TextWriter to save a string to a file in any encoding you like. Upvote 0
Tayfur Well-Known Member Licensed User Longtime User Feb 16, 2016 #7 can I do wtih like sample php code PHP >> chr() B4A>>chr () is it same? PHP >> ord() B4A>>?? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2016 #8 You don't need it. Let TextWriter do the job for you. Upvote 0
Tayfur Well-Known Member Licensed User Longtime User Feb 16, 2016 #9 Thank @Erel your fast answer... Upvote 0