c# - c#中连字符的不间断字符是什么?

标签 c# wpf unicode

我使用“\u00A0”将空格替换为不间断空格。 我需要相同的连字符(破折号)。 c# 中最好的解决方案是什么?

我尝试添加建议的字符,但是“?”出现而不是“-”。在调试中,我可以在转换过程中看到“-”,但最终是“?”。

我在其他帖子中发现不是实际破折号的“-”可能会导致“?”而不是破折号! ( Post regarding "-" and "?" ) 我需要一个解决方案,因为我需要一个不间断的破折号......

public void SetText(string text)
    {
        if (Mode == ControlMode.DesignTime)
        {
            string textToUse = string.Empty;
            string offlineScreenText = text;
            if (offlineScreenText != null)
            {
                int lblLen = Math.Min(Convert.ToInt32(_settings.MultilineLength), offlineScreenText.Length);
                textToUse = lblLen > 0 ? offlineScreenText.Substring(0, lblLen) : offlineScreenText;
            }

            _textBox.Text = textToUse;
        }
        else
        {
            if (!VerifyNumericValidity(text))
            {
                return;
            }

            _lastValue = text;

            // if there's a length limit, apply it to _lastValue 
            ApplyLengthLimit();

            if (text.Length > _textBox.MaxLength)
            {
                text = text.Substring(0, _textBox.MaxLength);
            }

            // Convertion to whitespaces in order to ignore the difference 
            // between non-breakable space ("\u00A0") and whitespaces (" ")
            string whitespacesText = text.Replace(" ", "\u00A0");
            whitespacesText = text.Replace("-", "\u2011");
            if (!whitespacesText.Equals(_textBox.Text) && !whitespacesText.Equals(_textBox.Text.TrimEnd()))
            {
                _textBox.Text = text;
            }
        }            
    }

void _textBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        int origCursorLocation = _textBox.SelectionStart;

        // Simple whitespeces aren't being wrapped normally, 
        // so we'll replace them with non-breakable spaces
        _textBox.Text = _textBox.Text.Replace(" ", "\u00A0");
        _textBox.Text = _textBox.Text.Replace("-", "\u2011");

        BindingLayer.RaisePresentationChanged(DependencyPropertyType.Text, _textBox.Text);

        _textBox.SelectionStart = origCursorLocation;
    }

最佳答案

这应该是您需要的连字符

"\u2011"

这里有一个特殊字符列表:http://wiki.mobileread.com/wiki/Special_characters

关于c# - c#中连字符的不间断字符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37569669/

相关文章:

c# - 基于类的GUI代码生成

c# - 需要在 C# 中优先处理异步套接字读取

c# - 重叠投影效果

c# - 如何将 Unicode 值转换为 ASCII 字符串?

python - utf-8 中的汉字字符

c# - 在参数中使用带有 Unicode 字符的 Windows 中的 GhostScript 9.10

c# - 为什么波浪号和斜杠在 Asp.net MVC 应用程序中不起作用?

c# - 服务层如何适合我的存储库实现?

c# - Mapsui 错误 : How to fix PresentationSource is null?

WPF DragDrop.DoDragDrop(右键单击?)