substr का उपयोग
substr दो positions के बीच text के एक piece से एक slice काटता है, एक ribbon पर scissors इस्तेमाल करने की तरह। आप बताते हैं कहाँ से शुरू करें और कहाँ रुकें।
In this page:
Syntax
substr(x, start, stop)
substr
substr(x, start, stop) दी गई character positions के बीच एक substring extract करता है, दोनों ends inclusive, 1-based indexing इस्तेमाल करते हुए। substr() एक assignment के left side पर भी इस्तेमाल हो सकता है string के हिस्से को in place replace करने के लिए।
यह position से strings slice करने का R का built-in तरीका है।
Note:
कई languages के उलट, substr() का stop index inclusive है -- substr("hello", 1, 3) "hel" देता है, position 3 समेत।
उदाहरण: substr
text <- "Hello, R World!"
cat(substr(text, 1, 5), "\n")
cat(substr(text, 8, 8), "\n")
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. #}
आम गलतियां
- start position की तरह 0 इस्तेमाल करना, जब R strings position 1 से शुरू होती हैं।
substr(text, 1, 5)को start और length से confuse करना, जब third argument end position है।text[1] <- "J"जैसे index से एक string बदलने की कोशिश करना, जो पूरी string replace करता है;substr(text, 1, 1) <- "J"इस्तेमाल करें।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: