D
D
Denis Shavaleev2021-06-24 13:42:39
Conveyor
Denis Shavaleev, 2021-06-24 13:42:39

How to cut a string at "/"?

Good day to all.
Such a moment. When writing a pipeline in the Groovy language, the functions of which include taking a link from a list and taking only certain parts from this link.
Currently implemented like this:

for(url in listUrls){
     var1 = url.split('/')[-1]
     var2 = url.split('.')[2]
     .................. 
     //Далее идет работа по использованию данных переменных
}

But when executing this snippet, it looks like this
mistake

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: [Ljava.lang.String;.split() is applicable for argument types: (java.lang.String) values: [/]
Possible solutions: split(groovy.lang.Closure), wait(), init(), sort(), tail(), toList()

I didn't get any leads when I searched the internet. I decided to turn to the good old Habr community. How can I split a string on a separator as "/"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2021-06-24
@Shavaleev_DieZ

String mylist[]=url.split("/");
var1=mylist[0];
var2=mylist[1];

So?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question