2014-06-10 38 views
-4

我試圖用藏族字符替換「」「་」ཚེག在WPF富文本框VS 2010我如何用「་」replace替換WPF Richtextbox?

可以說我有帶文本的格式文本框,如下所示:

སྐད བརྡའི སྒྲིག རིམ སྐྲུན པའི་ 

以下是我期望通過使用WPF richTextBox得到的輸出。

སྐད་བརྡའི་སྒྲིག་རིམ་སྐྲུན་པའི་ 

我有一個語言的鍵盤:

Monlam BOD-yig3.01的Unicode TCRCKB-

+0

你說的「差距」在這裏是什麼意思?請用英文寫下你的問題。 –

+0

感謝你的迴應,差距就像是(སྐདབརྡའིསྒྲིགརིམསྐྲུནཔའི་)字之間的空格,順便說一句對不對的解釋:) – verena

+0

請告訴我,如果我是對的。你有一個充滿文本的富文本框。在那篇文章中,你想用「་」替換所有''(空格)ཚེག –

回答

0

請訪問以下鏈接供你參考:automatic replacement of text in wpf richtextbox


通過Picrofo Software

因爲System.Windows.Controls.RichTextBox沒有噸有一個屬性Text檢測到它的價值,你可以使用以下

string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; 

然後發現它的價值,你可能會改變_Text並使用發佈新的字符串以下

_Text = _Text.Replace("pc", "Personal Computer"); 
if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) 
{ 
new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; 
} 

所以,倒是這個樣子

string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; 
_Text = _Text.Replace("pc", "Personal Computer"); // Replace pc with Personal Computer 
if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) 
{ 
new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; // Change the current text to _Text 
} 

備註:不要使用的你可以宣佈List<String>在其中保存的特徵及其替代品

例子:

List<string> _List = new List<string>(); 
    private void richTextBox1_TextChanged(object sender, TextChangedEventArgs e) 
    { 

     string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; 
     for (int count = 0; count < _List.Count; count++) 
     { 
      string[] _Split = _List[count].Split(','); //Separate each string in _List[count] based on its index 
      _Text = _Text.Replace(_Split[0], _Split[1]); //Replace the first index with the second index 
     } 
     if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) 
     { 
     new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; 
     } 
    } 

    private void Window_Loaded(object sender, RoutedEventArgs e) 
    { 
     // The comma will be used to separate multiple items 
     _List.Add("pc,Personal Computer"); 
     _List.Add("sc,Star Craft"); 

    } 

這裏的用戶試圖用個人電腦取代PC, 可以效仿將「'替換爲」་「same同樣的行爲。

如果這不是你的需求,你可以嘗試以下步驟滿意:

  1. 養TextChangedEvent爲RichTextBox的

  2. 檢查文本「」,從EventArgs的

  3. 如果爲true,則從RichTextBox.Text中刪除一個字符並添加「་」ཚེག

編輯:請參閱SELECT語句(雖然這是一個粗略的方法,並且將是有用的,只有當你選擇後鍵入)

string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; 
_Text = _Text.Replace(" ", "「་」ཚེག"); // Replace pc with Personal Computer 
if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) 
{ 
new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text+" "; // Change the current text to _Text 
} 
richTextBox1.Selection.Select(_Text.Length-1, _Text.Length); 
+0

@verena:請使用評論功能問作者不要試圖編輯帖子。 –

相關問題