How to parse this string?

I have this string: "0000A000"
How would I be able to group the zeros to get a string like this: 4A3

here is my take on it!

Code
String c0(String input) {
  String output = "";
  int z = 0;
  for (int i = 0; i < input.length(); i++) {
    if (input.charAt(i) == '0') {
      z++;
    } else {
      if (z != 0) {
        output += z;
        z = 0;
      }
      output += input.charAt(i);
    }
  }
  if (z != 0) {
    output += z;
    z = 0;
  }
  return output;
}
void setup() {
  println(c0("0000A000B00C0D"));
}
void draw() {
}

1 Like

Thank you! I will try implementing this. That snippet of code is for a chess game in which the engine needs FENstring to calculate moves. I’m using stockfish as the engine.

1 Like

Okay, I just tried implenting this and it worked. Thank you!

1 Like