简体   繁体   中英

Jenkins Pipeline - Groovy string function to remove trailing comma

Probably a super easy one to answer, but in aa Jenkins Pipeline script, what string function can I use to strip off a trailing comma from a string I have defined.

For example:

def fooBar = 'foo, bar,'

Thanks

If you know the comma is the last character, as in the hardcoded literal that referenced in the question, you could do something like this:

def fooBar = 'foo, bar,'
def result = fooBar[0..-2]

If you don't know the comma is the last character, you could find it by doing something like fooBar.lastIndexOf(',') and use that value to retrieve the characters before and after the comma and concatenate them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM