# How to parse this string?

**URL:** <https://discourse.processing.org/t/how-to-parse-this-string/27362>\
**Category:** Coding Questions\
**Created:** [January 25, 2021, 2:31pm UTC](https://discourse.processing.org/t/how-to-parse-this-string/27362 "2021-01-25T14:31:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SNICKRS](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SNICKRS](https://discourse.processing.org/u/SNICKRS)\
**Post date:** [January 25, 2021, 2:31pm UTC](https://discourse.processing.org/t/how-to-parse-this-string/27362/1 "2021-01-25T14:31:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 25, 2021, 2:43pm UTC](https://discourse.processing.org/t/how-to-parse-this-string/27362/2 "2021-01-25T14:43:14Z")

</div>

here is my take on it!

> **Code**
>
> ```auto
> 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() {
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![SNICKRS](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SNICKRS](https://discourse.processing.org/u/SNICKRS)\
**Post date:** [January 25, 2021, 2:51pm UTC](https://discourse.processing.org/t/how-to-parse-this-string/27362/3 "2021-01-25T14:51:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SNICKRS](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SNICKRS](https://discourse.processing.org/u/SNICKRS)\
**Post date:** [January 25, 2021, 2:53pm UTC](https://discourse.processing.org/t/how-to-parse-this-string/27362/4 "2021-01-25T14:53:36Z")

</div>

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