0

Hello I am trying to make a Quipu system where 1 is -x- and 2 is -xx- so a number like -x-xxx-xx- should return 132.

I wrote this:

String q = "-x-xxx-xx-";

  if(q.contains("-x-")) {
      System.out.println(1);
  }
  if(q.contains("-xx-")) {
      System.out.println(2);
  }
  if(q.contains("-xxx-")) {
      System.out.println(3);
  }

But it gives it in wrong order. I understand why because it finds the two before the three but if you could give me any ideeas how could i do it to give the exact String order. Thanks

S C
  • 73
  • 7
  • http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java might be helpful – Marius Loewe Feb 28 '17 at 12:12
  • Loop through the string characters. count the number of x until the next - character. The print the count. Repeat until you reach the end of the string. Exactly like you do it when reading and parsing the quipu "in your head" – JB Nizet Feb 28 '17 at 12:12
  • q.replaceAll("xxx", "3").replaceAll("xx", "2").replaceAll("x", "1").replaceAll("-", "") <- Doesn't validate if the input string is correct, but if it is this will work for your case. – OH GOD SPIDERS Feb 28 '17 at 12:17
  • Thanks works with split: – S C Feb 28 '17 at 13:01

0 Answers0