Hello, a username is Michael.Bontont
How can I extract the first letter of the first name (Michael) and first letter of the last name (Bontont)?
There is a problem with the type of argument.
Hello, a username is Michael.Bontont
How can I extract the first letter of the first name (Michael) and first letter of the last name (Bontont)?
There is a problem with the type of argument.
I do not think that String does not have a method named slice
in Java.
Have you invented it yourself?
No. I will try to use substring () method.
You had better use String.split(String delimiter)
method.
How to use String method, Split
Groovy - split() (tutorialspoint.com)
How to use String method, Substring
Groovy - subString() (tutorialspoint.com)
String clientName = "Michael.Bontont"
List<String> names = clientName.split("\\.")
StringBuffer sbuf = new StringBuffer()
for (int cnt = 0; cnt < names.size(); cnt++) {
sbuf.append(names.get(cnt).substring(0,1))
}
WebUI.comment("abbreviated name is ${sbuf}")
@grylion54 Thanks a lot! It works!
names = [Michael, Bontont]
get(0) = Michael - substring(0,1)=M
get(1) = Bontont - substring(0,1)=B