Answer the question
In order to leave comments, you need to log in
Java language. Split a string into substrings by a specific delimiter?
There is a task - to break the term and drive it into an array according to a certain separator
String[] arrayMessage;
String textMessage = "David>Mark:Привет Mark, как дела?[message]Login>David:Привет David, как дела?[message]
Login>Lenan:Привет Lenan, как дела?[message]Kriss>Serega:Привет Serega, как дела?[message]";
//В этой строке [message] является разделителем подстрок
//Необходимо загнать так, чтобы получилось вот так
arrayMessage[0] = "David>Mark:Привет Mark, как дела?";
arrayMessage[1] = "Login>David:Привет David, как дела?";
arrayMessage[2] = "Login>Lenan:Привет Lenan, как дела?";
arrayMessage[3] = "Kriss>Serega:Привет Serega, как дела?";
Answer the question
In order to leave comments, you need to log in
The matter is that it is necessary to escape square brackets in the regular expression and then everything will turn out =)
textMessage.split("\\[message\\]");
In short, I realized that I need to come up with a regular expression for split (), but I don’t know how
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question