String Methods का परिचय
String methods text के लिए built-in tools हैं जो case बदल सकते हैं, length measure कर सकते हैं, या spaces trim कर सकते हैं। यह हर word के लिए एक toolbox ready रखने जैसा है।
In this page:
Syntax
string.length
string.upcase
string.downcase
string.include?("text")
string.reverse
String Methods
Ruby strings transformation और inspection के लिए built-in methods का एक बड़ा set के साथ आती हैं, जैसे .upcase, .downcase, .reverse, .length, और .strip।
ज़्यादातर string methods original modify करने की बजाय एक नई string return करते हैं, non-mutating operations के लिए Ruby की general preference follow करते हुए। ! से खत्म होने वाले methods (जैसे .upcase!) इसकी बजाय string को in place mutate करते हैं।
Note:
! से खत्म होने वाला एक method (जैसे upcase!) आमतौर पर receiver को in place mutate करता है -- non-! version इसकी बजाय एक नया object return करता है।
उदाहरण: String Methods
text = " Hello, Ruby! "
puts text.strip
puts text.strip.upcase
puts text.strip.length
puts text.strip.reverse
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. #}
आम गलतियां
- यह उम्मीद करना कि
text.striptextबदल देगा, जब यह एक नई string return करता है जब तक आपstrip!इस्तेमाल न करें। upcase!जैसा एक bang method call करना और result इस्तेमाल करना, जब कुछ न बदलने पर यहnilreturn करता है।lengthको bytes की संख्या से confuse करना, जब Ruby characters count करता है (bytes के लिएbytesizeइस्तेमाल करें)।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: