- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 04:40 PM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2022 07:03 PM
@Tim zhang ,
thanks for your code, and here is your answer
I asked this question in Stackoverflow and got this answer
Here is the Stackoverflow link- https://stackoverflow.com/questions/74845760/how-to-parse-a-pattern-and-use-it-to-format-a-string-us...
Please select my this answer as the best answer,it will be really encouraging
Thanks
Aviral Bhardwaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2022 10:22 PM
Hey @Tim zhang ,
This is silly answer but this can give you some idea
or you can use for loop here,
Thanks
Aviral
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2022 07:03 PM
@Tim zhang ,
thanks for your code, and here is your answer
I asked this question in Stackoverflow and got this answer
Here is the Stackoverflow link- https://stackoverflow.com/questions/74845760/how-to-parse-a-pattern-and-use-it-to-format-a-string-us...
Please select my this answer as the best answer,it will be really encouraging
Thanks
Aviral Bhardwaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 05:47 PM
did you get any time to cehck above response @Tim zhang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 07:26 PM
yea, it works! Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:10 PM
@Tim zhang can you please upvote my answer and make it as best answer,it will be great help

