# How to handle spaces in export code

**URL:** https://community.mp3tag.de/t/how-to-handle-spaces-in-export-code/57196
**Category:** Export
**Created:** [May 3, 2022, 1:07am UTC](https://community.mp3tag.de/t/how-to-handle-spaces-in-export-code/57196 "2022-05-03T01:07:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rlangbell](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/6a8cbe/32.png) [@rlangbell](https://community.mp3tag.de/u/rlangbell)
#### Post date: [May 3, 2022, 1:07am UTC](https://community.mp3tag.de/t/how-to-handle-spaces-in-export-code/57196/1 "2022-05-03T01:07:04Z")

</div>

Sorry for the dumb question, but I'm having issues trying to get hard spaces to obey in output.  
My code is:  
`

```auto
$filename(txt,utf-8)
   Sort on Track
   Track Length Bitrate BPM Key Filename                                                                                                                                                        

$loop(%track%) %track% - Length: %_length% secs Bitrate: $left(%_bitrate% kbit/s ,3) BPM: $left(%bpm% ,3) Key: $left(%initialkey% ,3)	- $left(%_filename_ext%,45)
$loopend()

```

The results shows the Key column and Filename Column don't print the same length. How do I pad spaces in the function so that they line up properly? Look at tracks 106, 107, 109.

Also, is there a way to total the length field?

```auto
   Track Length Bitrate BPM Key - Filename                                                                                                                                                        

  101 - Length: 06:02 secs Bitrate: 128 BPM: 136 Key: Gm - Lido Shuffle LIve - Boz Scaggs.mp3
  102 - Length: 03:46 secs Bitrate: 128 BPM: 120 Key: Am - Cold Sweat - Boneshakers.mp3
  103 - Length: 04:30 secs Bitrate: 192 BPM: 121 Key: Em - Josie - Steely Dan.mp3
  104 - Length: 02:50 secs Bitrate: 128 BPM: 134 Key: Dm - Get Ready - Rare Earth.mp3
  105 - Length: 04:59 secs Bitrate: 128 BPM: 109 Key: Fm - Spooky - Atlanta Rhythm Section.mp3
  106 - Length: 04:30 secs Bitrate: 128 BPM: 101 Key: E - Let It Roll - Little Feat.mp3
  107 - Length: 04:42 secs Bitrate: 176 BPM: 100 Key: Gm - Don't Change Horses - Tower of Power.mp3
  109 - Length: 03:32 secs Bitrate: 186 BPM: 101 Key: Ebm - VEHICLE (Live) - The Ides Of March.mp3
  110 - Length: 05:30 secs Bitrate: 192 BPM: 119 Key: Gm - Sly Medley Mixdown - Gary.mp3
9 songs 40 min 21 sec

```

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [May 3, 2022, 5:33am UTC](https://community.mp3tag.de/t/how-to-handle-spaces-in-export-code/57196/2 "2022-05-03T05:33:11Z")

</div>

Do you really want to get a plain text file with a table in the end?  
If this output is to be fed to a formatter that understands tab characters, then use $char(9) as separator between the columns.

If you really need space characters then something like  
%initialkey%$repeat( ,$sub(8,$len(%initalkey%))  
where "8" is the maximum column width of your choice.  
As you have a fair number of text constants in each line (which is why I don't understand why you need column headers and vice versa, if you have column headers why repeat the data descriptor in each line ... but that is up to you), you may calculate the column width either including them or leaving then out.

Another remark:

> [@rlangbell](#):
>
> `$left(%_bitrate% kbit/s ,3) `

Such a statement does not make a lot of sense: if you take the 3 leftmost characters from a string like "128 kbit/s " then you end up with just "128" and all the trailing text will be cut off anyway. If you want to get just the number in 3 digits, use $num(%\_bitrate%,3) and add the embroidering text then as text constant.

> [@rlangbell](#):
>
> Also, is there a way to total the length field?

Have a look at the documenation:

> **[Format Strings and Placeholders – Mp3tag Documentation](https://docs.mp3tag.de/format/)**
>
> Documentation on format strings and placeholders to describe the structure of file names and imported data. Mp3tag is the universal Tag Editor.

and the global variables for export which features among others  
`%_total_time%` Total playing time (formatted output)
