Differences between version 4 and previous revision of ManipulatingStrings.
Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 4 | Last edited on Monday, December 11, 2006 12:59:55 pm | by BenStaz | Revert |
Older page: | version 3 | Last edited on Monday, December 11, 2006 12:39:15 pm | by BenStaz | Revert |
@@ -19,4 +19,35 @@
echo ${test:4:3} will return just "dog"
The 4 tells us the index of the char that will be the first char in the substring. The 3 tells us how many letters to add starting at the index.
+
+!Remove Substrings
+
+Strips *shortest* match of $substring from *front* of $string.
+*${string#substring}
+
+For example if $string contained "This is a string" and we replaced substring with ''T*'' an echo would result in
+''his is a string''
+
+
+
+Strips *longest* match of $substring from *front* of $string.
+*${string##substring}
+
+For example if $string contained "This is a string" and we replaced substring with ''T*'' an echo would result in an empty string. (The longest match was the entire string).
+
+
+
+Strips *shortest* match of $substring from *back* of $string.
+*${string%substring}
+
+For example if $string contained "This is a string" and we replaced substring with ''s*'' an echo would result in
+''This is a''
+
+
+
+Strips *longest* match of $substring from *back* of $string.
+*${string%%substring}
+
+For example if $string contained "This is a string" and we replaced substring with ''s*'' an echo would result in
+''Thi'' (The longest match)