0
我沒有在用阿拉伯語書寫的文本內的RichBox工具,一個變音符號,並且當您搜索阿拉伯語詞組變音時,標記不會正確地將該單詞着色爲你看:搜索Richbox工具爲阿拉伯語的單詞忽略格式在WPF
但是,如果你搜索在沒有注音符號的話,這將是地板着色正確,你看:
這個搜索代碼,我使用,我覺得現在的問題是,所以我希望你將它修改爲我:
Dim NumSearch As Integer
NumSearch = 0
Dim keyword As String = ReplaceString(TxtSearch.Text.Trim)
Dim text As New TextRange(RichTxtPost.Document.ContentStart, RichTxtPost.Document.ContentEnd)
Dim current As TextPointer = text.Start.GetInsertionPosition(LogicalDirection.Forward)
While current IsNot Nothing
Dim textInRun As String = ReplaceString(current.GetTextInRun(LogicalDirection.Forward))
'If Not String.IsNullOrWhiteSpace(textInRun) Then
If Not String.IsNullOrEmpty(textInRun) Then
Dim index As Integer = textInRun.IndexOf(keyword)
If index <> -1 Then
Dim selectionStart As TextPointer = current.GetPositionAtOffset(index, LogicalDirection.Forward)
Dim selectionEnd As TextPointer = selectionStart.GetPositionAtOffset(keyword.Length, LogicalDirection.Forward)
Dim selection As New TextRange(selectionStart, selectionEnd)
NumSearch = Val(NumSearch) + 1
'selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold)
selection.ApplyPropertyValue(TextElement.ForegroundProperty, New SolidColorBrush(Colors.Red))
RichTxtPost.Selection.[Select](selection.Start, selection.[End])
RichTxtPost.Focus()
End If
End If
current = current.GetNextContextPosition(LogicalDirection.Forward)
End While
此替換功能,以取代簡介:
Public Function ReplaceString(In_Text As String) As String
'خاص بالبحث مع تجاهل التشكيل
Dim X As Long
Dim strChar As String
Dim strReturn As String
strReturn = ""
For X = 1 To Len(In_Text)
strChar = Mid(In_Text, X, 1)
Select Case strChar
Case "أ", "إ", "آ"
strChar = "ا"
Case "ه"
strChar = "ة"
Case Chr(243), Chr(240), Chr(245), Chr(246), Chr(242), Chr(241), Chr(248), Chr(250)
''حذف علامات التشكيلية إذا وجد، وهي
'
'' َ ً ُ ِ ٍ.
'strChar = ""
' يجب اضافة حرف وهمي غير مستخدم في النص الاساسي بدلا من كل حرف مطلوب تجاهله سواء همزة او شكله
strChar = ""
End Select
strReturn = strReturn & strChar
Next
ReplaceString = strReturn
End Function