2016-06-01 3 views
0

"\ u00A0"を使用して空白を改行しないスペースとして置き換えます。 ハイフン(ダッシュ)には同じものが必要です。 C#のそれのための最良の解決策は何ですか?c#のハイフンの改行文字は何ですか?

編集:私は文字を追加しようとしましたが、 "?" " - "の代わりに表示されます。デバッグでは変換中に " - "が見えますが、最終的には "?"が見えます。

実際のダッシュではない " - "が "?"ダッシュの代わりに!これは、あなたがここでの特殊文字のリストがあり

"\u2011" 

必要ハイフンでなければなりません

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; 
    } 

答えて

3

私は非破壊ダッシュを必要とするので、私はそのためのソリューションを必要とする(Post regarding "-" and "?")...: http://wiki.mobileread.com/wiki/Special_characters

+0

ありがとうございます!それは私がやろうとしたことですが、なんらかの理由でこのキャラクターが "?"に変わりました。 UI内で:( – MTZ

+0

関連するコードを表示することができます - それは私のWPFテキストボックスで動作します – PaulF

+0

コード上に追加ありがとう! – MTZ

関連する問題