String Literals और Escapes
Strings quotes में लिखी जाती हैं, और special characters एक backslash के साथ लिखे जाते हैं।
In this page:
String Literals और Escapes
Strings single quotes, double quotes, या long brackets [[ ... ]] इस्तेमाल कर सकती हैं जो कई lines तक फैलते हैं और escapes ignore करते हैं। Common escapes हैं newline के लिए \n, tab के लिए \t, एक backslash के लिए \\ और एक quote के लिए \"। Lua 5.3 \x41 hexadecimal और \u{48} Unicode escapes भी support करता है। Strings immutable हैं, इसलिए operations हमेशा नई strings return करते हैं।
Note:
Long brackets multi-line text के लिए perfect हैं और ]] contain करने के लिए [==[ ... ]==] जैसे levels इस्तेमाल कर सकते हैं।
उदाहरण: String literals and escapes
print('single', "double")
print("tab:\there, quote: \"q\"")
print("hex \x41 and unicode \u{48}")
print([[long
string \n stays raw]])
print("a\\b")
-- Output:
-- single double
-- tab: here, quote: "q"
-- hex A and unicode H
-- long
-- string \n stays raw
-- a\b
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- same तरह के quotes के अंदर एक quote escape करना भूल जाना
- यह उम्मीद करना कि escapes [[ ]] के अंदर काम करेंगे
- in place एक character बदलने की कोशिश करना
चैप्टर सारांश
- ' " या [[ ]] इस्तेमाल करें
- \n \t \\ common escapes हैं
- Long brackets escapes ignore करते हैं
- Strings immutable हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: