Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

ManipulatingStrings

String length

To determine a string's length, the shortest is:

${#var}

Trimming Strings

${var/pattern/rep}
Replace the first instance of pattern in var by rep. If pattern starts with *, this replaces pattern and everything that precedes it with rep.
${var/%\pattern/rep}
Replace the last instance of pattern in var by rep. If pattern ends with *, this replaces pattern and everything that follows it with rep.

To remove the selection, simply leave rep empty.

Combinations

The above can be used together to obtain the substring between pattern1 and pattern2:

varTrimFront=${var/*pattern1/}
varTrimFrontAndBack=${varTrimFront/%\pattern2*/}
echo $varTrimFrontAndBack
Edit - History - Print - Recent Changes - Search
Page last modified on May 16, 2018, at 02:28 PM