- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2022 02:39 PM
Thanks a lot of your replay @Aviral Bhardwaj
I try to not hard code it and eventually turn it to a function. This is a initial raw code, but it has problem,
val pattern="XX-***-XXXX-***";
val item="abcdefghijkl"
val patternindex=pattern.lastIndexOf("-");
val patternupdated= pattern.substring(0,patternindex);
var lenplus = pattern.indexOf("-")
var fitem=item.patch(lenplus, "-", 0)
val result = patternupdated.split("-")
for ( a
{
val len= a.length()
// Displays output
lenplus = len + lenplus+1
fitem= fitem.patch(lenplus, "-", 0)
println(fitem)
}
The result is wrong,
ab-cd-efghijkl
ab-cd-efg-hijkl
ab-cd-efg-hijk-l