-
April 16th, 2014, 07:06 PM
#1
.Find Ignore case
Code:
Private Sub SortColour()
Dim ObjectList As New List(Of String)
For i As Integer = 1 To lstObjects.Items.Count - 1
ObjectList.Add(lstObjects.Items(i).ToString)
Next
Dim L As Integer = rtbRoom.TextLength
For Each word As String In ObjectList
Dim lastindex = rtbRoom.Text.LastIndexOf(word)
Dim index As Integer = 0
While index < lastindex
rtbRoom.Find(word, index, L, RichTextBoxFinds.None)
rtbRoom.SelectionColor = Color.Lime
index = rtbRoom.Text.IndexOf(word, index) + 1
End While
Next
End Sub
HI, looking for some friendly advice.
Can anyone please tell me how I can get the above code to be NOT case sensitive.
I've tried all sorts but can't fathom it. Any help will be greatly appreciated.
-
April 17th, 2014, 10:56 AM
#2
Re: .Find Ignore case
Convert one to Lowecase (or upper), and then do a compare.
-
April 17th, 2014, 11:24 AM
#3
Re: .Find Ignore case
hi dglienna. Thanks for your reply.
If you're saying what I think you are. Then I'm certain I've tried this already.
At the moment, I have a workaround but I really don't like it. It's basically repeating the same code twice.
UnEdited:
Code:
Private Sub SortColour()
Dim ObjectList As New List(Of String)
For i As Integer = 1 To lstObjects.Items.Count - 1
ObjectList.Add(lstObjects.Items(i).ToString)
Next
Dim rb(4) As RichTextBox
rb(1) = rtbAfterOpen
rb(2) = rtbAfterTurn
rb(3) = rtbExamine
rb(4) = rtbOpenExamine
For I = 1 To 4
Dim L As Integer = rb(I).TextLength
For Each word As String In ObjectList
Dim lastindex = rb(I).Text.LastIndexOf(word)
Dim index As Integer = 0
While index < lastindex
rb(I).Find(word, index, L, RichTextBoxFinds.None)
rb(I).SelectionColor = Color.Lime
index = rb(I).Text.IndexOf(word, index) + 1
End While
Next
Next
For i As Integer = 1 To lstObjects.Items.Count - 1
ObjectList.Add(lstObjects.Items(i).ToString.ToLower)
Next
For I = 1 To 4
Dim L As Integer = rb(I).TextLength
For Each word As String In ObjectList
Dim lastindex = rb(I).Text.LastIndexOf(word)
Dim index As Integer = 0
While index < lastindex
rb(I).Find(word.ToLower, index, L, RichTextBoxFinds.None)
rb(I).SelectionColor = Color.Lime
index = rb(I).Text.IndexOf(word, index) + 1
End While
Next
Next
End Sub
Edited for ease of reading
Code:
Private Sub SortColour()
Dim ObjectList As New List(Of String)
For i As Integer = 1 To lstObjects.Items.Count - 1
ObjectList.Add(lstObjects.Items(i).ToString)
Next
Dim rb As RichTextBox = rtbTemp
Dim L As Integer = rb.TextLength
For Each word As String In ObjectList
Dim lastindex = rb.Text.LastIndexOf(word)
Dim index As Integer = 0
While index < lastindex
rb.Find(word, index, L, RichTextBoxFinds.None)
rb.SelectionColor = Color.Lime
index = rb.Text.IndexOf(word, index) + 1
End While
Next
'Repeat the above. Converting to lower.
For i As Integer = 1 To lstObjects.Items.Count - 1
ObjectList.Add(lstObjects.Items(i).ToString.ToLower)
Next
For Each word As String In ObjectList
Dim lastindex = rb.Text.LastIndexOf(word)
Dim index As Integer = 0
While index < lastindex
rb.Find(word.ToLower, index, L, RichTextBoxFinds.None)
rb.SelectionColor = Color.Lime
index = rb.Text.IndexOf(word, index) + 1
End While
Next
End Sub
I don't like "cheating" I think it's bad practice. So this is just a temporary fix until I can find the correct solution.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|