Home java Java, page PARS

Java, page PARS




There is a row of type HAT523HAT524HAT525 . Tell me, please, how can you split this line like this:

c1 = "HAT523";
C2 = "HAT524";
C3 = "HAT525"; `

Answer 1, Authority 100%

You can use a regular expression. Flexib and possibly any number of matches.

Pattern Pattern = Pattern.compile ("Hat52 \\ D");
  String Line = "HAT523HAT524HAT525";
  Matcher Matcher = Pattern.matcher (Line);
  String [] Array = New String [3];
  For (int i = 0; matcher.find (); i ++) {
    Array [i] = Matcher.group ();
  System.out.PrintLN (Array.Tostring (Array));

Answer 2

You can use the SUBSTRING () method.

string s = "hat523hat524hot525";
String C1, C2, C3;
c1 = s.substring (0, 6);
C2 = S.Substring (6, 12);
C3 = S.SUBSTRING (12);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions