简体   繁体   中英

Whats the difference between these two strings?

Using nUnit to test the output (currency formatting) for a specific culture but we are getting the following result.

  Fail: Formatting currency amount
  String lengths are both 11. Strings differ at index 2.
  Expected: "12 765,87 €"
  But was:  "12 765,87 €"
  -------------^

We can't see the difference between the strings. Our expected result uses a "Space" character.

Is there a different space character that we can put into the accepted result to get the test to pass?

By the way, the tested culture is fr-FR.

Edit: Thanks Adam you are spot on with the unicode character. We have changed our expected results and now each Unit test passes.

It's possible they're different types of spaces. Unicode has a lot of different space characters . Take a look at the code points at index 2 by casting the characters to integers to get your answer.

Edit

In response to your comment, code point 160 is a non-breaking space . You can enter it directly into your source code (eg Alt+0160 on the numeric keypad on Windows), or use an escape sequence:

// U+20AC is the Unicode code point for the euro sign
string expected = "12\u00A0765,87 \u20AC";

很可能是空白字符,而不是空格,以避免标签,并且在启用自动换行时会将数字一分为二。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM