c#中连字符的非中断字符是什么?

c#中连字符的非中断字符是什么?,c#,wpf,character,hyphen,C#,Wpf,Character,Hyphen,我使用“\u00A0”将空格替换为非中断空格。 我需要同样的连字符(破折号)。在c#中,最好的解决方案是什么 编辑:我试图添加建议的字符,但显示“?”而不是“-”。在debug中,我可以在转换过程中看到“-”,但最终会看到“-” 我在另一篇博文中发现“-”不是真正的破折号可能导致“?”而不是破折号!()我需要一个解决方案,因为我需要一个不间断的冲刺 public void SetText(string text) { if (Mode == ControlMode.Des

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

编辑:我试图添加建议的字符,但显示“?”而不是“-”。在debug中,我可以在转换过程中看到“-”,但最终会看到“-”

我在另一篇博文中发现“-”不是真正的破折号可能导致“?”而不是破折号!()我需要一个解决方案,因为我需要一个不间断的冲刺

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"

这里有一个特殊字符列表:

谢谢!这就是我试图做的,但出于某种原因,这个字符在UI中更改为“?”:(你能显示相关代码吗?它在我的WPF文本框中工作。上面添加的代码。谢谢!我不确定BindingLayer.RaisePresentationChanged(DependencyPropertyType.Text,_textbox.Text)是什么,但你的代码对我来说是正确的(没有问号,连字符按预期显示)。需要注意的一点是,在SetText中,您用替换的空格初始化WhiteSpaceText-toText,然后立即用替换的连字符覆盖该文本,因此空格将回到那里-您可以用string WhiteSpaceText=text.replace(“,“\u00A0”)。replace(“-”,“\u2011”)。你是否更改了文本框的字体,否则我就没主意了。