Page 1 of 1

Convert Strings to and from UTF8 byte arrays ...

PostPosted: Wed Jan 08, 2020 7:52 pm
by bosibila
Hello to all members,
is there any way to convert this Java code to FWH (getBytes method):

Code: Select all  Expand view
*
*
*
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

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

PostPosted: Wed Jan 08, 2020 8:20 pm
by karinha

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

PostPosted: Wed Jan 08, 2020 8:50 pm
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

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

PostPosted: Thu Jan 09, 2020 12:37 pm
by karinha
Maybe,

Code: Select all  Expand view

#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.


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

PostPosted: Thu Jan 09, 2020 12:48 pm
by karinha

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

PostPosted: Tue Jan 14, 2020 6:53 am
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.