I have sequences of characters I'm feeding to a decoding function:
我给解码函数输入了一系列字符:
For example:
例如:
"\x05three"
(Yes, that's a Pascal-style string. The function translates length-prefixed strings to null-terminated strings.)
(是的,这是一个帕斯卡风格的字符串。函数将长前缀字符串转换为空终止字符串。
I wrote a few test cases, among which:
我写了一些测试案例,其中包括:
"\x04four"
And to my surprise, that came out as "Oour". Looking closer, it turns out that the specification on escape sequences for Visual Studio allows that, my sequence is basically interpreted as \x04f
, which would be 79 in base 10 (thus my resulting string becomes "Oour", 79 being 'O')
令我惊讶的是,这句话竟然是“Oour”。仔细看,Visual Studio的转义序列规范允许,我的序列基本上被解释为\x04f,以10为基数将是79(因此,我的结果字符串变成了“Oour”,79表示“O”)
My solution was simply to split the string:
我的解决办法就是把绳子分开:
"\x04" "four"
The question: Is there another way to escape or terminate an escape sequence?
问题是:是否有其他方法可以转义或终止转义序列?
1 个解决方案
#1
5
Yes, you cant try "\004four"
for instance. Actually, even "\04four"
will probably do, because f
is not an octal number.
是的,你不能试试“\ 0044”。实际上,即使是“\ 044”也可能会发生,因为f不是一个八进制数。
#1
5
Yes, you cant try "\004four"
for instance. Actually, even "\04four"
will probably do, because f
is not an octal number.
是的,你不能试试“\ 0044”。实际上,即使是“\ 044”也可能会发生,因为f不是一个八进制数。