Double Byte numbers in asp.net

Double Byte numbers in asp.net

灵芸 发布于 2021-12-01 字数 802 浏览 788 回复 3 原文

We are developing a site that has a Japanese localization. In that site, we display several dynamic fields using asp:label and such controls.

Recently, we were required to display numbers using "double-byte characters".

While it first I thought that was a confusion from the client, he sent me this in an email:

1234567890
1234567890

and this shows I was wrong, and that indeed there are "wider" number characters available.

Any hint on how to make ASP.NET switch to those dynamically?

Update: The second sample seems be called "FULLWIDTH" characters. The question could be rephrased as:

How do I make ASP.NET automatically display FULLWIDTH numbers when the current culture is JP?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转瞬即逝 2022-06-07 3 楼

Here is a function to do it:-

    static string IntToWideNumbers(int n)
    {
        char[] chars = n.ToString().ToCharArray();
        for (int i = 0; i < chars.Length; i++)
        {
            chars[i] = (char)((uint)chars[i] ^ 0xFF20);
        }
        return new String(chars);
    }
七秒鱼° 2022-06-07 2 楼

You're confusing font width with DBCS. If you just want a wider font, use the appropriate CSS. If you actually want to support unicode and use wide characters, you need to implement your backend using the appropriate data type.

By default all strings in C# are Unicode. You can control encoding following techniques outlined here.

仅此而已 2022-06-07 1 楼

Apparently, there are some other characters in unicode that look just like the 'normal' numbers, but display wider by default.

Here's the text from your question pasted into notepad, saved as unicode, and run through XXD:

0000000: fffe 3100 3200 3300 3400 3500 3600 3700  ..1.2.3.4.5.6.7.
0000010: 3800 3900 3000 0d00 0a00 11ff 12ff 13ff  8.9.0...........
0000020: 14ff 15ff 16ff 17ff 18ff 19ff 10ff 0d00  ................
0000030: 0a00 0a                                  ...

It looks like where '1' is 0x0031, 'special 1' is 0xff11. If using CSS to display the 'normal' numbers, but with a wider font isn't an option, I'd say you'll have to take the number, convert it to a string, add 0xff10 to every character between 0x0030 and 0x0039 to get what you're looking for.