在ColdFusion中将字符串转换为utf-8 Unicode [英] Convert string to utf-8 unicode in ColdFusion
问题描述
我需要将字符串转换为UTF8编码格式,但不确定如何继续.
I need to convert a string to a UTF8 encoded format and I'm not sure how to proceed.
ColdFusion中是否有任何函数可以将字符串转换为UTF-8,例如在网站上?
Is there any function within ColdFusion to convert a string into UTF-8, such as on this website?
例如,在上述网站中输入"stackoverflow.com/questions/ask" 即可得到结果:
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 \ x65 \ x73 \ x74 \x69 \ x6F \ x6E \ x73 \ x2F \ x61 \ x73 \ x6B
\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
我对编码不是很熟悉,但是我的指令是将字符串编码为UTF-8.给出的示例给出了以下示例的编码结果.
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/
/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?
谢谢!
推荐答案
我认为您可以结合使用 CharsetEncode()完成此操作.
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")>
您只需要替换在我的示例中,对于"ASCII" 正确的初始编码.
You'd just need to substitute the correct initial encoding for "ASCII" in my example.
这篇关于在ColdFusion中将字符串转换为utf-8 Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!