如何逃避或终止C中的转义序列 [英] How to escape or terminate an escape sequence in C

查看:132
本文介绍了如何逃避或终止C中的转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我喂养解码功能的字符序列:

I have sequences of characters I'm feeding to a decoding function:

例如:

"\x05three"

(是的,这是一个Pascal风格的字符串,功能转换与长度prefixed字符串以空结尾的字符串)。

(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"

让我吃惊,说出来的OOUR。仔细一看,原来,在转义序列为Visual Studio允许,我的顺序是PTED为 \\ x04f 基本上间$ p $,这将是79基10(因此我得到的字符串变为OOUR,79被'O')

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')

我的解决办法是简单地分割字符串:

My solution was simply to split the string:

"\x04" "four"

的问题是:是否有另一种方式来逃避或终止转义序列

推荐答案

是的,你不能尝试\\ 004four的实例。其实,即使\\ 04four可能会做,因为˚F不是八进制数。

Yes, you cant try "\004four" for instance. Actually, even "\04four" will probably do, because f is not an octal number.

这篇关于如何逃避或终止C中的转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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