String की Length
String length एक name tag पर letters count करने जैसा है। Bash एक छोटी trick से आपको बता सकता है कि आपके text में कितने characters हैं।
In this page:
Syntax
${#variable_name}
String Length
${#variable} एक string variable में characters की संख्या देता है। यह wc जैसी external command call किए बिना string length check करने का एक fast, built-in तरीका है। यह syntax Bash की parameter expansion feature का हिस्सा है।
Note:
wc -c से pipe करने के बजाय ${#var} उपयोग करें — यह एक subprocess शुरू करने से बचता है।उदाहरण: String Length
#!/bin/bash
name="Hello, Bash!"
echo "Length: ${#name}"
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. #}
आम गलतियां
- एक array पर
${#var}उपयोग करना और items की संख्या के बजाय पहले element की length मिलना। #भूल जाना, जैसे${var}, जो सिर्फ value देता है।- यह उम्मीद करना कि
${#var}bytes count करेगा, जब यह एक UTF-8 locale में characters count करता है।
🔒
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: