Skip to Content

String value convert to UTF-8

Jul 06, 2017 at 12:28 PM


avatar image

Hi Gurus,

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

URLParameterEntry.Value = this.GetFirst().grad


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

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.



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

Hello Zoran,

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

. Horst

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

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();

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

Please help if you have other idea:-)


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?

. Horst

Zoran Galijanic Jul 20, 2017 at 06:28 AM

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.



10 |10000 characters needed characters left characters exceeded