R
R
roman38472014-04-06 15:55:05
Java
roman3847, 2014-04-06 15:55:05

Java String is it possible to go through the entire string sequentially and find a match?

For example in the string "qwertyqw". If I meet "qwe", then I need to replace it with "1", and if "ty", then replace it with 2. And in the end it should turn out: "1r2qw".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dexdev, 2014-04-06
@roman3847

regular expressions to help you

E
Evgeny Ulyanov, 2014-04-07
@eoltemniyelf

Overheard from a friend: "If you have a problem that you want to solve with regular expressions, you already have two problems."
Try like this:
"qwertyqw".replace("qwe", "1").replace("ty", "2");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question