Substring निकालना
Substring extraction एक लंबी ribbon से एक slice काटने जैसा है। आप बताते हैं कहां से cutting शुरू करनी है और कितना लंबा piece चाहिए।
In this page:
Syntax
${variable:start:length}
${variable:start}
Substring Extraction
${variable:start:length} एक given index (0-based) से एक given number of characters के लिए string का एक हिस्सा extract करता है। length छोड़ने से start से end तक सब कुछ extract होता है।
यह दूसरी languages में मिलने वाले एक substring function का Bash का built-in equivalent है।
Note:
एक negative
start, जैसे ${var: -3}, string के end से extract करता है (minus से पहले required space पर ध्यान दें)।उदाहरण: Substring Extraction
#!/bin/bash
text="Hello, Bash World!"
echo "${text:0:5}"
echo "${text:7:4}"
echo "${text:7}"
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. #}
आम गलतियां
${str:1:3}उपयोग करना और3को end index मानना, जब यह length है।- यह भूल जाना कि offsets 0 से शुरू होते हैं।
- बिना space के एक negative offset उपयोग करना, जैसे
${str:-3}, जिसका मतलब है एक default value;${str: -3}लिखें।
🔒
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: