如何创建新的转义序列?

时间:2022-06-05 00:02:57

Is it possible to make a whole printf() string be converted toupper() or tolower() automatically via an escape sequence? How to do that?

是否可以通过转义序列自动转换整个printf()字符串toupper()或tolower()?怎么做?

Escape sequence are those that having "\" back slash when printing. tolower() enables you to convert uppercase letter to lowercase. toupper() enables you to convert lowercase letter into uppercase. But is it possible to make/add an escape sequence that also have the same function of tolower() and toupper(). For example, I'm going to create new escape sequence "\u" and "\l". \u as the toupper() and it will be used like this.

转义序列是在打印时具有“\”反斜杠的序列。 tolower()使您可以将大写字母转换为小写。 toupper()使您可以将小写字母转换为大写。但是是否可以创建/添加一个转义序列,它也具有与tolower()和toupper()相同的功能。例如,我将创建新的转义序列“\ u”和“\ l”。 \ u作为toupper(),它会像这样使用。

printf("\u hello world");

Output:

输出:

HELLO WORLD

The string next to the escape sequence will be converted to uppercase letters. It is also the same with the \l as tolower(). How to do that? Please help me.

转义序列旁边的字符串将转换为大写字母。它与\ l和tolower()也是一样的。怎么做?请帮帮我。

3 个解决方案

#1


1  

Is it possible to make a whole printf() string be converted toupper() or tolower() automatically via an escape sequence?

是否可以通过转义序列自动转换整个printf()字符串toupper()或tolower()?

No, you cannot do that.

不,你做不到。

The escape sequences are defined by the language. You can't add to them.

转义序列由语言定义。你无法添加它们。

#2


1  

  • You can make new function as Printf_new() and in that you can parse
  • 您可以将新功能设置为Printf_new(),并且可以解析
  • its argument and get \i or \u and depending upon that
  • 它的论点并得到\ i或\ u并依赖于此
  • call toupper() and tolower() convert your string and then again
  • 调用toupper()和tolower()转换你的字符串然后再次
  • call original printf()
  • 叫原始printf()

#3


0  

No. This isn't in any way possible.

不,这绝不是可能的。

#1


1  

Is it possible to make a whole printf() string be converted toupper() or tolower() automatically via an escape sequence?

是否可以通过转义序列自动转换整个printf()字符串toupper()或tolower()?

No, you cannot do that.

不,你做不到。

The escape sequences are defined by the language. You can't add to them.

转义序列由语言定义。你无法添加它们。

#2


1  

  • You can make new function as Printf_new() and in that you can parse
  • 您可以将新功能设置为Printf_new(),并且可以解析
  • its argument and get \i or \u and depending upon that
  • 它的论点并得到\ i或\ u并依赖于此
  • call toupper() and tolower() convert your string and then again
  • 调用toupper()和tolower()转换你的字符串然后再次
  • call original printf()
  • 叫原始printf()

#3


0  

No. This isn't in any way possible.

不,这绝不是可能的。