- 论坛徽章:
- 1
|
对字符串的操纵有很多方法,我就不多说了,这几天在读bash的guide,发现了一个有意思的,(或许大家都知道,我还是发出来,就算灌水吧 )
- # Is it possible to index from the right end of the string?
-
- echo ${stringZ:-4} # abcABC123ABCabc
- # Defaults to full string, as in ${parameter:-default}.
- # However . . .
- echo ${stringZ:(-4)} # Cabc
- echo ${stringZ: -4} # Cabc
- # Now, it works.
- # Parentheses or added space "escape" the position parameter.
- # Thank you, Dan Jacobson, for pointing this out.
复制代码
我们知道,对string的从左到右的操作很简单,这个tips讲的是从右到左如何操作,我作了几个实验,感到确实很有 意思 大家感兴趣的可以玩玩! |
|