Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to utf-8 unicode in ColdFusion

I need to convert a string to a UTF8 encoded format and I'm not sure how to proceed.

Is there any function within ColdFusion to convert a string into UTF-8, such as on this website?

For example, typing in "stackoverflow.com/questions/ask" into the above website gives the result:

\x73\x74\x61\x63\x6B\x6F\x76\x65\x72\x66\x6C\x6F\x77\x2E\x63\x6F\x6D\x2F\x71\x75\x65\x73\x74\x69\x6F\x6E\x73\x2F\x61\x73\x6B

I am not very familiar with encoding, however my instructions were to encode a string to UTF-8. The example I was given gave an encoded result of the below for example.

/re/r/434/t//4r3/t434/4t/t3/3/4t/43tt/53/

I am not sure if this is a real representation of an encoded string or if it was just typed out to give a visual example. Is there a format that looks like that? And is it different than the format from the first example?

Thank you!

like image 629
MerrickC Avatar asked Oct 07 '16 19:10

MerrickC


1 Answers

I think you can use a combination of CharsetDecode() and CharsetEncode() to accomplish this.

<cfset my_string = "test">
<cfset binary_my_string = CharsetDecode(my_string, "ASCII")>
<cfset utf8_my_string = CharsetEncode(binary_my_string, "utf-8")>

You'd just need to substitute the correct initial encoding for "ASCII" in my example.

like image 179
user2540711yo Avatar answered Sep 23 '22 12:09

user2540711yo