jeudi 29 novembre 2018

Find a pattern at certain location in a String and replace it with something else in Java

I’m facing a weird problem that I cant resolve for some reason. If I have this String: “aaaa aa” And the pattern is: “aa” So there is 3 places that match that pattern: (aa)(aa)( aa) I want to change the pattern at specific location (let’s say at the second position) with something else, let’s say this String: “bbb”.

So the final result will be: “aabbb aa”.

What is the simplest way to solve this? Without any special collection or special classes.

Aucun commentaire:

Enregistrer un commentaire