当前位置:网站首页>[escape character] [full of dry goods] super detailed explanation + code illustration!
[escape character] [full of dry goods] super detailed explanation + code illustration!
2022-07-03 05:38:00 【Sobtemesa】
Escape character , seeing the name of a thing one thinks of its function , First , It is One character , Secondly, its meaning has changed , But it is still a character .
stay C In language , Characters are and ascii The tables correspond one by one , Characters can be represented in two ways , One uses it Entity ( That is, the real character , for example 'A') Express , You can also use a backslash inside single quotation marks to add ascil Code value ( Such as '\130''---->'X' ) Express , This way of using encoded values to indirectly represent characters is called escape characters .
Escape characters to \
perhaps \x
start , With \
The beginning represents the encoded value followed by octal form , With \x
The beginning represents the encoded value followed by hexadecimal form . For escape characters , Only octal or hexadecimal can be used . These two transfer characters represent A byte Integer value character of size .
\ddd | ddd Express 1~3 Eight octal numbers . Such as \130----> 'X' |
\xdd | dd Represents two hexadecimal digits . Such as \x30 ---> '0' |
Students can try printf once "\x48\x45\x4C\x4C\x4F\x20\x57\x4F\x52\x4C\x44\x0A" See what it is .
character 1、2、3、a、b、c Corresponding ASCII The octal forms of the codes are 61、62、63、141、142、143, The hexadecimal forms are 31、32、33、61、62、63.
The following example demonstrates the use of escape characters :
Escape characters are intended for ASCII code , So it's The range of values is limited :
- Escape characters in octal form can be followed by up to three digits , That is to say
\ddd
, The maximum value is\177-->(127( Decimal system ))
; - Escape characters in hexadecimal form can be followed by up to two numbers , That is to say
\xdd
, The maximum value is\x7f-->(127( Decimal system ))
.
The behavior of escape characters that are out of range is undefined , Some compilers will output the encoded value directly , Some compilers report errors .( Attached with one ascii surface )
But writing like this is a little troublesome , You can't just watch ascii clock , While writing code , So use it to entity like 'A' This is easier , But this will not solve all the problems ,ascii Those in the code Control characters ( Nonprinting characters ) They are invisible , Cannot be displayed on the display , You can't even type... From the keyboard , There is no way to use this direct input method , Only use \ddd perhaps \xdd Way to print , But we know it's troublesome , Use it directly ASCII Code memory is inconvenient , It's not easy to understand , therefore , For common control characters ,C Language is defined again Shorthand way , For example, we use some symbols to help remember to replace numbers , For example, use n To replace hexadecimal digits 'A','\x0A' I can write this as '\n' 了 . The complete list is shown in the figure .
Escape character | paraphrase | ASCIL Code value |
\" | Double quotes | 034 |
\' | Single quotation marks | 039 |
\\ | The backslash ( One ) | 092 |
\n | Line break (LF) , Moves the current position to the beginning of the next line | 010 |
\f | Change the page (FF), Move the current position to the beginning of the next page | 012 |
\b | Backspace (BS) , Move the current position to the previous column | 008 |
\a | Ring the bell (BEL) | 007 |
\r | enter (CR) , Move the current position to the beginning of the line | 013 |
\t | Horizontal TAB (HT) | 009 |
\v | Vertical tabulation (VT) | 011 |
Let's have a few codes to feel : Serve ~~~~
1.
Don't get the string length wrong !\32 Is a character
2.
- Single quotation marks are the beginning and end of character types , To use
\'
Express , That is to say'\''
; - Double quotes are the beginning and end of a string , To use
\"
Express , That is to say"abc\"123"
; - The backslash is the beginning of the escape character , To use
\\
Express , That is to say'\\'
, perhaps"abc\\123"
3. use \ hold \ If you escape it, you can print out the value we want
Dear comrades, have you learned to waste ~~~
~~~
Blow out the reading lamp , It's all about the moon .
You have to refuel tomorrow .
边栏推荐
- Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
- NG Textarea-auto-resize
- About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
- How to set up altaro offsite server for replication
- 一起上水硕系列】Day 9
- Shanghai daoning, together with American /n software, will provide you with more powerful Internet enterprise communication and security component services
- Source insight License Activation
- 获取并监控远程服务器日志
- AtCoder Beginner Contest 258(A-D)
- Final review (Day2)
猜你喜欢
2022.DAY592
Today, many CTOs were killed because they didn't achieve business
How do I migrate my altaro VM backup configuration to another machine?
Simpleitk learning notes
配置xml文件的dtd
BTC-密码学原理
3dslam with 16 line lidar and octomap
Technical analysis of qianyuantong multi card aggregation router
【一起上水硕系列】Day 10
Redis cannot connect remotely.
随机推荐
Source insight automatic installation and licensing
聊聊如何利用p6spy进行sql监控
Differences among bio, NiO and AIO
2022.7.2 simulation match
Obtenir et surveiller les journaux du serveur distant
Introduction to rust Foundation (basic type)
获取并监控远程服务器日志
穀歌 | 蛋白序列的深度嵌入和比對
獲取並監控遠程服務器日志
The IntelliJ platform completely disables the log4j component
Altaro set grandfather parent child (GFS) archiving
Classification and discussion of plane grab detection methods based on learning
Capacity expansion mechanism of map
Source insight License Activation
3dslam with 16 line lidar and octomap
2022.7.2 模拟赛
chromedriver对应版本下载
Calculation method of AUC
Together, Shangshui Shuo series] day 9
Skip table: principle introduction, advantages and disadvantages of skiplist