# How can I keep leading and trailing spaces in a parsed string?

**URL:** https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491
**Category:** Web Sources Discussion
**Created:** [December 12, 2021, 6:46pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491 "2021-12-12T18:46:06Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 12, 2021, 6:46pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/1 "2021-12-12T18:46:06Z")

</div>

I'm still learning the syntax of the Web Source language.

If I parse a JSON result, I get a string called JOINPHRASE which can include leading and trailing spaces like in the string `" feat. "` (which would be `space feat. space`)

You can see that correct result - including the leading space - in the script line debug output for line 391.  
The code snippet starting with line 391:

```auto
                    json_select "JOINPHRASE"
                    ifnot ""
                        GotoChar 1
                        sayrest
                        say " "
                    endif                    
                json_foreach_end
                say "|"

```

Debug output:

```auto
------------------------------------------------------------
Script-Line : 391
Command : json_select
Parameter 1 : >joinphrase<

Output : >Olivia Rodrigo|The Kid LAROI<

Line and position:
 feat. 
^
------------------------------------------------------------
Script-Line : 392
Command : ifnot
Output : >Olivia Rodrigo|The Kid LAROI<

Line and position:
 feat. 
^

------------------------------------------------------------

Script-Line : 105
Command : gotochar
Parameter 1 : >1<

Output : >Olivia Rodrigo|The Kid LAROI<

Line and position:
 feat. 
^

------------------------------------------------------------

Script-Line : 106
Command : sayrest

Output : >Olivia Rodrigo|The Kid LAROIfeat.<

Line and position:
 feat. 
     ^

------------------------------------------------------------

Script-Line : 107
Command : say
Parameter 1 : > <

Output : >Olivia Rodrigo|The Kid LAROIfeat. <

Line and position:
 feat. 
     ^
------------------------------------------------------------

```

But even my attempt with `GotoChar 1` doesn't help to get the full, untrimmed content of JOINPHRASE. You can see the missing space for `feat.` if you look at the result in script line #106

_(BTW I have no idea, why the script jumps from #392 to #105 and returns later after #107 back to #397`json_foreach_end` after the I`fNot-EndIf`)_

What can I do get this result:  
`Olivia Rodrigo|The Kid LAROI feat.`  
without manually adding leading or trailing spaces to the mentioned JOINPHRASE?

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 12, 2021, 7:23pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/2 "2021-12-12T19:23:20Z")

</div>

You can only use the `json_...` functions to navigate when in JSON mode, so no `gotochar` for you there.

See [How to Say to output without trimming whitespace?](https://community.mp3tag.de/t/how-to-say-to-output-without-trimming-whitespace/53276) for a similar topic which describes the trimming of whitespace you're observing.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 12, 2021, 7:49pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/3 "2021-12-12T19:49:16Z")

</div>

Do we have any chance that we can use such results (at least for JSON) untouched?

According to the [help](https://docs.mp3tag.de/tag-sources) you alreay offer the command

```
Unspace - Removes leading and trailing spaces from the current line

```

for those who want to trim such content.

It would be great if the content would be left untouched otherwise.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 12, 2021, 7:55pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/4 "2021-12-12T19:55:03Z")

</div>

> [@Florian](#):
>
> You can only use the `json_...` functions to navigate when in JSON mode, so no `gotochar` for you there.

That made me feel very insecure.

Could you please mark all the non available commands for JSON in the [help](https://docs.mp3tag.de/tag-sources)? Or the other way around if it helps...

Or would it be easier to mark such commands in the debug output with something like "not possible in JSON"? Currently, I don't see any hint that `GotoChar` (for example) doesn't work at all.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 12, 2021, 8:15pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/5 "2021-12-12T20:15:02Z")

</div>

I think I spoke too early, `gotochar` is also working in JSON mode, so no need to feel insecure.

> [@LyricsLover](#):
>
> According to the [help](https://docs.mp3tag.de/tag-sources) you alreay offer the command
> 
> ```auto
> Unspace - Removes leading and trailing spaces from the current line
> 
> ```
> 
> for those who want to trim such content.

Yes, but many rely on the current behavior and changing it now would mean more support overhead. As you can imagine, answering questions regarding tag sources is mostly my task here (dano and pone have been a huge help there in the past) and it's always a huge time sink, especially without minimal examples.

I'll think about a way to turn on trimming whitespace on output. I could imagine a dedicated function `Trim "off|on"` which would turn the auto-trimming off and on respectively.

Are you experimenting just out of interest or do you want to develop (and maintain) an alternative MusicBrainz tag source?

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 12, 2021, 8:36pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/6 "2021-12-12T20:36:28Z")

</div>

> [@Florian](#):
>
> Are you experimenting just out of interest or do you want to develop (and maintain) an alternative MusicBrainz tag source?

I try to create a JSON MusicBrainz web source script. If it also work for compilations like "Bravo Hits" - where I struggle currently - I would share it here. I'm pretty sure that a JSON version of `MusicBrainz#Artist - Album.src` would be more stable and easier to maintain then the XML or even web site parsing with his dozens of regular expressions.

> [@Florian](#):
>
> I could imagine a dedicated function `Trim "off|on"` which would turn the auto-trimming off and on respectively.

That would be really useful! 🎄 🎁 🎅

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 13, 2021, 3:35pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/7 "2021-12-13T15:35:33Z")

</div>

I've added `Trim "off|on"` to this preliminary version for you to try.

[https://download.mp3tag.de/support/BEC24A86-ECE4-4F65-BC75-A439E84B7B86-3-11-6-2/mp3tagv311f2setup.exe](https://download.mp3tag.de/support/BEC24A86-ECE4-4F65-BC75-A439E84B7B86-3-11-6-2/mp3tagv311f2setup.exe)

`Trim "off"` disables the automatic trimming of whitespace on all the `Say...` commands, `Trim "on"` re-enables it (the default).

---

<div class="post-metadata">

### Author: ![mr\_bug](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@mr\_bug](https://community.mp3tag.de/u/mr_bug)
#### Post date: [December 13, 2021, 4:23pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/8 "2021-12-13T16:23:33Z")

</div>

> [@Florian](#):
>
> I've added `Trim "off|on"` to this preliminary version for you to try.

Thanks for this! Will give it a test.

And in case you're wondering @LyricsLover, [the previous solution](https://community.mp3tag.de/t/how-to-say-to-output-without-trimming-whitespace/53276/7) has been working fine, but this new `trim` feature will be a much less hacky approach.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 13, 2021, 4:38pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/9 "2021-12-13T16:38:56Z")

</div>

I had to update the preliminary version, so if you got v3.11f1 please make sure to update to v3.11 **f2** from the link above.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 13, 2021, 5:48pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/10 "2021-12-13T17:48:54Z")

</div>

v3.11f2 works great in my first attempts. 🥰

Thank you very much! 👏  
It makes this case a lot easier.

---

<div class="post-metadata">

### Author: ![mr\_bug](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@mr\_bug](https://community.mp3tag.de/u/mr_bug)
#### Post date: [December 13, 2021, 6:24pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/11 "2021-12-13T18:24:05Z")

</div>

`trim` is confirmed as working as intended here too.

There is an issue I'd consider similar when it comes to writing multiple tags of the same name for a single track ([post](https://community.mp3tag.de/t/write-multiple-tags-of-the-same-name-to-a-single-track/55506)).

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [January 14, 2022, 4:04pm UTC](https://community.mp3tag.de/t/how-can-i-keep-leading-and-trailing-spaces-in-a-parsed-string/55491/12 "2022-01-14T16:04:41Z")

</div>

This is now officially part of [Mp3tag v3.11h](https://community.mp3tag.de/t/455).
