Shell----String interception method Induction

Source: Internet
Author: User

SHELL---string interception


1, by the specified string interception (4 kinds)

${varible##*string} # to truncate the strings after the last string from left to right < delete the left character, leaving the right character >

${varible#*string} # to truncate the strings after the first string from left to right < delete the left character, leaving the right character >

${variblepercent string*} # intercepts the string after the last string from right to left < removes the right character, leaving the left character >

${varible%string*} # intercepts the string after the first string from right to left < Deletes the right character, leaving the left character >

Note: varible variable name

String to be intercepted by string

"*" is just a wildcard can not


Examples and operating results:

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/82/D9/wKiom1dib53wNm3fAADwjzFW1lw749.jpg "title=" ##%%. JPG "alt=" wkiom1dib53wnm3faadwjzfw1lw749.jpg "/>


2, according to the specific character offset and length, using another form of variable extension, to select a specific substring. (4 types)

This form of string truncation is simple, with only a colon separated to specify the starting character and substring length.

${varible: Start:len} # starts with the left (start+1) character and the number of characters Len

${varible:start} # starts from the left (start+1) character until the end of the page

${varible: 0-start:len} # starts with the first character on the right and the number of characters Len

${varible: 0-start} # starts with the start character on the right and ends at the end of the page

Note: varible variable name

start character begin position the first character on the left is denoted by 0, and the first character on the right is denoted by 0-1.

Len Character Count

Examples and operating results:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/82/DA/wKiom1difsiDSEfMAADx1I51c0I646.jpg "title=" ::: 2.jpg "alt=" Wkiom1difsidsefmaadx1i51c0i646.jpg "/>


This article is from the "Flower Open Shore" blog, please be sure to keep this source http://zxtong.blog.51cto.com/10697148/1790030

Shell----String interception method Induction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.