Convert Strings to and from UTF8 byte arrays ...

Convert Strings to and from UTF8 byte arrays ...

Postby bosibila » Wed Jan 08, 2020 7:52 pm

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

Code: Select all  Expand view  RUN
*
*
*
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
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

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

Postby karinha » Wed Jan 08, 2020 8:20 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7835
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

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

Postby bosibila » Wed Jan 08, 2020 8:50 pm

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
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia

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

Postby karinha » Thu Jan 09, 2020 12:37 pm

Maybe,

Code: Select all  Expand view  RUN

#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 - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7835
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


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

Postby bosibila » Tue Jan 14, 2020 6:53 am

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)
User avatar
bosibila
 
Posts: 53
Joined: Wed Aug 06, 2008 5:27 pm
Location: Osijek, Croatia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 101 guests