groovy风格字符串截取

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);

猜你喜欢

转载自blog.csdn.net/alittleyatou/article/details/82591654