Convert Strings to and from UTF8 byte arrays ...

Post Reply
User avatar
bosibila
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Convert Strings to and from UTF8 byte arrays ...

Post by bosibila »

Hello to all members,
is there any way to convert this Java code to FWH (getBytes method):

Code: Select all

*
*
*
protected static byte[] getTest(String httpMethod, String methodUri, String username, String password)
{
String str = httpMethod + "\n" + methodUri + "\n" + username + "\n" + password;

return str.getBytes(UTF8);               /**return byte array**/
}
Thanks
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Convert Strings to and from UTF8 byte arrays ...

Post by karinha »

João Santos - São Paulo - Brasil
User avatar
bosibila
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Re: Convert Strings to and from UTF8 byte arrays ...

Post by bosibila »

Thanks João, but I think it is not applicable to my example. It is not charset convert.

When I send string to Java method 'getbytes' with this charactes:
cStr:="POST/eservice//batch/json/echoMyUserNamePass1234?"

Result is: "[B@1db9742" // UTF8 byte array
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Convert Strings to and from UTF8 byte arrays ...

Post by karinha »

Maybe,

Code: Select all

#include "FiveWin.ch"

REQUEST HB_CODEPAGE_PTISO

REQUEST HB_CODEPAGE_PT850

FUNCTION Main()

   local cStr, cAsc, cUtf8

   HB_SETCODEPAGE( "PT850" )

   cStr  := "Isto é um teste de conversão."

   cUtf8 := hb_strToUTF8( cStr )

   cAsc  := hb_UTF8ToStr( cUtf8 )

   ? cStr

   ? cUtf8

   ? cAsc

RETURN NIL
 
Regards, saludos.
João Santos - São Paulo - Brasil
User avatar
bosibila
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

Re: Convert Strings to and from UTF8 byte arrays (solved) ...

Post by bosibila »

Java method getbytes returns aray of character codes from string („ABCD“ -> {65,66,67,68}).
I tried to rewrite several pages of code without previous knowledge of Java, but it was much simpler writing this part of code in FiveWin.
Boris (FWH 20.07, xHarbour 1.2.3, Harbour 3.2.0, BCC74, MySql 5.7)
Post Reply