Multiline Strings कैसे लिखें
एक multiline string आपको text लिखने देता है जो कई lines में फैलता है exactly जैसे आप type करें, एक page पर एक poem की तरह। आपको special line-break marks की ज़रूरत नहीं।
In this page:
Syntax
text = "first line
second line"
puts text
Multiline Strings
एक Ruby string literal quotes के अंदर directly कई lines में फैल सकता है, line breaks को string के content के हिस्से की तरह preserve करते हुए। यह short multi-line text के लिए explicit \n characters इस्तेमाल करने से simpler है।
लंबे text blocks के लिए, एक heredoc (अगला cover होगा) आमतौर पर ज़्यादा readable है।
Note:
एक quoted string के अंदर सीधे type किए line breaks resulting string में literal newline characters बन जाते हैं।
उदाहरण: Multiline Strings
message = "Line one
Line two
Line three"
puts message
puts message.lines.count
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# 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. #}
आम गलतियां
- quotes के अंदर continuation lines में leading spaces add करना और output में इनकी उम्मीद न करना।
- quote close करना भूल जाना, इसलिए बाकी file string का हिस्सा treat होती है।
split("\n")से lines count करना जबlinesnewline characters रखता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: