Skip to Content
0

String value convert to UTF-8

Jul 06, 2017 at 12:28 PM

293

avatar image

Hi Gurus,

How can I convert string value from code bellow to UTF-8

URLParameterEntry.Value = this.GetFirst().grad

Br,

Zoran Galijanic

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Zoran Galijanic Jul 20, 2017 at 08:36 AM
0

Oh...I found the solution. I perform search string and replace with encoded URL values.

For the example above I use following code.

var encodeGrad = this.GetFirst().grad;
encodeGrad= encodeGrad.ToUpperCase();
encodeGrad = encodeGrad.Replace("Š", "%C5%A0");
URLParameterEntry.Value = encodeGrad;

Important Update!!!

File of absl code has to be saved with "advanced save options" & for encoding of source code you have to choose UTF-8!!!

Thanks Horst for support.

br,

Zoran

Share
10 |10000 characters needed characters left characters exceeded
Horst Schaude
Jul 06, 2017 at 01:35 PM
0

Hello Zoran,

If your read section 7.2.5.1.2 Binary (Reuse Library) in the documentation you will find that you can only convert binary to and from UTF-8.

Sorry,
. Horst

Share
10 |10000 characters needed characters left characters exceeded
Zoran Galijanic Jul 06, 2017 at 02:11 PM
0

Hi Horst,

Thanks for the answer.

But it seams that this doesn't work at least as expected. Actuality with following code I have to send request with POST method.

this.GetFirst().grad contain string with Croatian character. In user interface value is "Šibenik". If I send this to the REST api service I don't get an expected answer. Following code is working perfectly without Croatian characters.

var ScenarioNameCity = "RestGrad";
var ServiceNameCity = "RestGrad";
var HttpMethod = "POST";
var HttpResource = "";
var ContentType = "text/html;charset=UTF-8";
var Body = "";
var HeaderParameter : collectionof NameAndValue; 
var URLParameter : collectionof NameAndValue;
var URLParameterEntry : NameAndValue;

URLParameterEntry.Name = "grad";
var bin = Binary.ParseFromString(this.GetFirst().grad);
URLParameterEntry.Value = bin.ToString();
URLParameter.Add(URLParameterEntry);

var ws_result_city = WebServiceUtilities.ExecuteRESTService(ScenarioNameCity, ServiceNameCity, HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);

Please help if you have other idea:-)

br,

Zoran Galijanic

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hello Zoran,

The lines

var bin =Binary.ParseFromString(this.GetFirst().grad);
URLParameterEntry.Value= bin.ToString();

are actually doing nothing, right? From String to Binary to String?

BTW: Did you verify if the value is the same?

Does your WebService accept also other content types?

Bye,
. Horst

0
Zoran Galijanic Jul 20, 2017 at 06:28 AM
0

Hi Horst,

I know that in general those two lines are "doing nothing", but I thought that in background with this usage method "ParseFromString" UTF-8 conversion is done.

Web service accept also "application/x-www-form-urlencoded" content type.

Maybe additional hint:

this.GetFirst().grad in the user interface and C4C database is correctly stored and can be searched, create, update. The only problem is when with this value "Šibenik" web service is invoked. Then letter "Š" is somehow translated wrong. Also if I use non-specific Croatian characters web service is working perfect.

Eq. in c# I can solve this issue with following code

UTF8Encoding enconding = new UTF8Encoding();
string postData = "Šibenik";
byte[] data = enconding.GetBytes(postData);

This quite similar special character like "ü" in "München". And I assume that web service call that include parameter like stadt="München" will run into same problem if during post method "ü" is not converted somehow before sending data to server.

br,

Zoran

Share
10 |10000 characters needed characters left characters exceeded