在 ColdFusion 中将字符串转换为 utf-8 unicode [英] Convert string to utf-8 unicode in ColdFusion

查看:30
本文介绍了在 ColdFusion 中将字符串转换为 utf-8 unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将字符串转换为 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:

x73x74x61x63x6Bx6Fx76x65x72x66x6Cx6Fx77x2Ex63x6Fx6Dx2Fx71x75x65x73x74x69x6Fx6Ex73x2Fx61x73x6B

x73x74x61x63x6Bx6Fx76x65x72x66x6Cx6Fx77x2Ex63x6Fx6Dx2Fx71x75x65x73x74x69x6Fx6Ex73x2Fx61x73x6B

我对编码不是很熟悉,但是我的指令是将字符串编码为 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?

谢谢!

推荐答案

我认为你可以使用 CharsetDecode()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")>

您只需替换 the在我的示例中为 "ASCII" 正确的初始编码.

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

这篇关于在 ColdFusion 中将字符串转换为 utf-8 unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆