How to print .NET String.Format space character on a regular line?

I am working on strings in .Net Core. I have a string formatted using :n, and when it is formatted, output 123 456,00. I would like to argue that the formatted string is equal to the string I want, but I get Assert.Equal Failure(), and the problem is the space character. At the exit, he claims that the two spaces are different.

Here is my code:

public void Separator()
{
    var str = string.Format("{0:n}", 123456);
    Assert.Equal("123 456,00",str);
}

I also compared the space character from the formatted string with the regular space character with the statement as follows Assert.Equal(' ',str[3]);to get the expected value 0x00a.

Why is this happening and how can I get the same character without using string.Format()?

+4
1

, ASCII, . , ru-RU , , ASCII 160, , , .

:

var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
var stringToCompare = "123 456,00".Replace(
    " ", 
    currentCulture.NumberFormat.NumberGroupSeparator);

Assert.Equal(stringToCompare, str);
+4

Source: https://habr.com/ru/post/1684220/


All Articles