← Back to Lua Course | Chapter 3: Strings | Lesson 1 of 7

String Literals और Escapes

Strings quotes में लिखी जाती हैं, और special characters एक backslash के साथ लिखे जाते हैं।

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

lua
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
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. same तरह के quotes के अंदर एक quote escape करना भूल जाना
  2. यह उम्मीद करना कि escapes [[ ]] के अंदर काम करेंगे
  3. in place एक character बदलने की कोशिश करना
चैप्टर सारांश
  • ' " या [[ ]] इस्तेमाल करें
  • \n \t \\ common escapes हैं
  • Long brackets escapes ignore करते हैं
  • Strings immutable हैं

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.