Problem with hidden 'character' in a string, how do I remove?

Hi everyone,

I’m trying to work out why a string cannot be trimmed and it seems there’s some sort of hidden character at the start.

It simply shows as a blank space in Visual Code, but appears as a strange ‘symbol’ in PowerShell 7 preview, if I export the variable value to a txt file it doesn’t appear in notepad (however if I hold shift and right-key the cursor highlight the apparent first character on the first press and starts blinking between black and red - suggesting that a hidden character is present or something).

It’s hard to explain so I’ve attached a link to a screenshot that hopefully shows the logical steps I’ve taken to identify this.

PowerShell string containing unknown ‘character’

Does anybody have any ideas how I can remove this ‘thing’ ?

Thanks

I’ve resolved my problem using:-

$br = $br -replace $br[0],‘’

I’ve still no idea what the character is however (it looks like a rectangle standing on it’s shorter side).

Just a little hint for the next time you want to post code: An image of your code is not helpful.

Hi,

The image was included as there’s no other way for me to describe the character that’s showing up. I can’t even type the character on the keyboard to include in plain text.

If I knew how to include code that shows a hidden character I’d have shown the code.

Thanks.

What is the string from? I’ve heard of that before, maybe an alignment character adobe uses or something in the title of a file.

Hi,

I found a script online that extracts the meta data from an .mp3 file using Shell.Namespace.

The string in my example is value of the bit rate output from the mp3.

I wanted to simply extract the digits from the string so I could create an integer variable for bitrate instead but kept getting a conversion error and that’s when I noticed that the variable length was longer than the characters shown.

I eventually solved that by using -replace “[^0-9]”,‘’, but that doesn’t help me understand how or what the hidden character was in the first place.

I’m guessing there’s something specific/unique about the mp3 tag for bitrate that results in this strange occurrence in this instance.

Thanks.

Maybe some more explanation: If you post a question in a forum about some code it would be helpful for the people willing to help to actually see (or have) the code to be able to reproduce the behaviour or the error or whatever issue you have with this particular code. If you’re not able to share the actual code you shold share some example code to enable the helpers to reproduce your issue. :wink:

So if you have this code from a website you should either post the code or at least a link to the website.

I wonder if this might help you figure it out

For the curious in all of us, please post what you find. Thanks.