groovy風格字串擷取
阿新 • • 發佈:2018-11-03
1、擷取字串
def text1 = "My last character will be removed soon" println text1[0..-2] // My last character will be removed soo def text2 = "My first word will be removed soon"; println text2[3..-1] // first word will be removed soon def text3 = "noos em daer lliw uoy ,tneitap eB" println text3[-1..0] // Be patient, you will read me soon
2、將字串賦值給陣列
1)方式1
node { stage('cat issue') { withEnv(['JIRA_SITE=wzzjira']) { echo 'jira issue key:' echo "${params.JIRA_ISSUE_KEY2}" echo 'jira summary:' echo "${params.JIRA_ISSUE_KEY3}" echo 'jira LINK:' echo "${params.JIRA_ISSUE_KEY4}" def b="${params.JIRA_ISSUE_KEY4}" String a=b[1..-2] String[] str; str = a.split(', '); for(int i in str) { def c="${i}" echo "${c}" } } } }
2)方式2
def b=字串
String a=b[1..-2]
String[] str;
str = a.split(', ');
for( String values : str )
println(values);