C 中 符號的用法

2021-07-05 15:59:34 字數 605 閱讀 8517

1、用在表示路徑的字串前面

string filepath_error = "f:\t1\t2\t3.txt";//此時字串中'\'會被當做轉義字元處理,將不能正確表示路徑

string filepath_success = "f:\\t1\\t2\\t3.txt";//對'\'進行轉義,此時可以正確表示為路徑

string filepath_success1 = @"f:\t1\t2\t3.txt";//@ 符號加在字串前面表示其中的轉義字元將「不」被處理,此時也可以正確表示路徑

顯然最後一種既正確,又方便

2、可以讓字串跨行

普通跨行

string str1 = "this is line 1"

+ "this is line 2"

+ "this is line 3";

@跨行,不需要字串相加,可直接跨行,寫sql語句很方便

string str2 = @"this is line 1

this is line 2

this is line 3";

3、可以讓關鍵字作為識別符號(類名、變數名、方法名,命名空間等)

class @class

}

C 的符號用法 ?問號用法

在字串前加 相當於對string format 的簡化 如 int m a 1 int m b 2 使用string format console.writeline string format this is a this is b m a,m b 使用了 就可以在原來佔位符的地方直接用引數代替 ...

C 符號和 符號的用法介紹

1.忽略轉義字元 string str c windows system32 string str c windows system32 2.字串跨行 string str line one line two line three line fore string str line one line...

Python中符號的用法

1.如果字串內部既包含 又包含 怎麼辦?可以用轉義字元 來標識,比如 i m ok 表示的字串內容是 i m ok 轉義字元 可以轉義很多字元,比如 n表示換行,t表示製表符,字元 本身也要轉義,所以 表示的字元就是 可以在python的互動式命令列用print 列印字串看看 print i m o...