FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Convert Strings to and from UTF8 byte arrays ...
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
Convert Strings to and from UTF8 byte arrays ...
Posted: Wed Jan 08, 2020 07:52 PM
Hello to all members,
is there any way to convert this Java code to FWH (getBytes method):

Code (fw): Select all Collapse
*
*
*
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)
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Convert Strings to and from UTF8 byte arrays ...
Posted: Wed Jan 08, 2020 08:20 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
Re: Convert Strings to and from UTF8 byte arrays ...
Posted: Wed Jan 08, 2020 08: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)
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Convert Strings to and from UTF8 byte arrays ...
Posted: Thu Jan 09, 2020 12:37 PM
Maybe,

Code (fw): Select all Collapse
#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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Convert Strings to and from UTF8 byte arrays ...
Posted: Thu Jan 09, 2020 12:48 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 53
Joined: Wed Aug 06, 2008 05:27 PM
Re: Convert Strings to and from UTF8 byte arrays (solved) ...
Posted: Tue Jan 14, 2020 06: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)

Continue the discussion