c# - C# UNITY Unicode 表情符号显示
问题描述
我正在从源系统接收以下格式的表情符号。
- '\u2764' 代表❤</li>
- '\ud83d\udc4d' 为
我需要知道如何转换它,因此它在 Unity 调试日志和文本字段中显示为正确的表情符号。请帮我。
当我尝试下面的代码
socket = listener.Accept();
int bytesRec = socket.Receive(receiveBuffer);
data = Encoding.UTF8.GetString(receiveBuffer, 0, bytesRec);
Debug.Log(data);
我明白了
- '\u2764' 代表❤</li>
- '\ud83d\udc4d' 为
当我尝试下面的代码
socket = listener.Accept();
int bytesRec = socket.Receive(receiveBuffer);
data = Encoding.Unicode.GetString(receiveBuffer, 0, bytesRec);
Debug.Log(data);
我明白了
- '畜㜲㐶' for ❤</li>
- '畜㡤搳畜捤搴' for
谢谢乔斯
解决方案
代码,HTH:
Function Get-PythonString {
[CmdletBinding()]
[OutputType([System.String],[System.Int32[]])]
param(
[Parameter(Position=0, Mandatory, ValueFromPipeline)] [String]$pyStr='',
[Parameter()] [Switch] $AsArray
)
$retArr = [System.Collections.ArrayList]::new()
$retStr = ''
$highSur= ''
$i=0
while ( $i -lt $pyStr.Length ) {
if ( $pyStr.Chars($i) -eq '\' ) {
if ( $pyStr.Chars($i +1 ) -ceq 'U' ) {
$iAux = [int]("0x" + ($pyStr.Substring( $i+2, 8)))
$i += 10
} elseif ( $pyStr.Chars($i +1 ) -ceq 'u' ) {
$iAux = [int]("0x" + ($pyStr.Substring( $i+2, 4)))
$i += 6
} elseif ( $pyStr.Chars($i +1 ) -ceq 'x' ) {
$iAux = [int]("0x" + ($pyStr.Substring( $i+2, 2)))
$i += 4
} else {
$iAux = [int]$pyStr.Chars( $i )
$i++
}
} else {
$iAux = [int]$pyStr.Chars( $i )
$i++
}
if ( $iAux -gt 0xFFFF ) { # out of BMP } {
[void]$retArr.Add( [int]$iAux)
$retStr += [char]::ConvertFromUtf32( $iAux)
} else {
if ( [char]::IsHighSurrogate( [char]$iAux )) {
$highSur = [char]$iAux
} else {
if ( [char]::IsLowSurrogate( [char]$iAux )) {
$iAux = [int][char]::ConvertToUtf32( $highSur, [char]$iAux)
$highSur = ''
}
[void]$retArr.Add( [int]$iAux)
$retStr += [char]::ConvertFromUtf32( $iAux)
}
}
}
if ($AsArray.IsPresent) {
$retArr
} else {
$retStr
}
}
仅在 Python 字符串文字中识别的转义序列是:
Escape Sequence Meaning
\xnn Character with 8-bit hex value nn
\unnnn Character with 16-bit hex value nnnn
\Unnnnnnnn Character with 32-bit hex value nnnnnnnn
\N{name} Character named name in the Unicode database (not implemented)
用法示例:
Get-PythonString -pyStr "\x65\x78\x61\x6D\x70\x6C\x65, \u2764, \U0001F602 or \ud83d\udc4d"
example, ❤, or
"\x65\x78\x61\x6D\x70\x6C\x65, \u2764, \U0001F602 or \ud83d\udc4d"|Get-PythonString
example, ❤, or
推荐阅读
- nltk - NLTK 文本分类置信度朴素贝叶斯
- c - 使用英特尔 MKL 计算 `trans(a)*inv(b)*a` 的正确方法
- reactjs - 用于向下钻取表的反应库
- html - 如何制作不规则的div边框
- java - 从 IntelliJ Ultimate 2018.2.5 访问 MySQL 服务器
- java - 如何在更多 Apache POI Pivot 之间共享 Pivot Cache?
- python - 如何在 google colab 上升级 pandas
- python - 在 tensorflow 中使用 tf.data.Dataset api 恢复模型后在开发数据集上运行模型
- c# - 使用 Automapper 映射时如何更改属性?
- r - 计算字符串组合的频率