Replacing Non-Breaking Spaces with Regular Spaces in a String

Mike Bilz asked on August 28, 2020 20:30

Hello Everyone,

I am attempting to manipulate some messy data and am running into an issue with Kentico not treating spaces and non-breaking spaces the same within the Replace macro.

Is it possible to write a Replace function that will turn non-breaking spaces into standard spaces?

.Replace(" "," ") and .Replace(" "," ") have not been effective.

Thanks in advance.

-mike

Correct Answer

David te Kloese answered on August 29, 2020 00:15

Hi,

are you sure the code is not encoded? Or having a different case for the  ?

As replacing it should work:

Image Text

my test code:

1. '{% x = "X Y Z" @%}'
2. '{% x.Replace(" ", "_").ToString() @%}'
3. '{% x.Replace(" ", " ").ToString() @%}'
2 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.