Nick_Net2004 Posted June 2, 2004 Posted June 2, 2004 I have a string let say : "Public Servants Airfare" and I want to check if the string servants, no case sensitive if possible, is in how do I do that? Quote
Administrators PlausiblyDamp Posted June 2, 2004 Administrators Posted June 2, 2004 Dim s As String = "Public Servants Airfare" If s.ToLower.IndexOf("servants") >= 0 Then MessageBox.Show("Match found") End If bit of a hack but it should work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
AlexCode Posted June 2, 2004 Posted June 2, 2004 2 ways: 1 -> s.IndexOf("servants") 2 -> Use the Regex, find the right one for you and test it here: http://regexlib.com/ Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Nick_Net2004 Posted June 2, 2004 Author Posted June 2, 2004 By the way is this kind of search case sensitive? Quote
AlexCode Posted June 2, 2004 Posted June 2, 2004 IndexOf is case sensitive. That's why I told you to use the RegEx. But then PlausiblyDamp came up with than enginious idea... works! :p If you need multiple results whithin a string, then you'll have to use RegEx... sorry :-\ Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
*Experts* Bucky Posted June 2, 2004 *Experts* Posted June 2, 2004 Well, for multiple results you could use a loop, but in that case RegEx might be easier. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Nick_Net2004 Posted June 2, 2004 Author Posted June 2, 2004 Here what I use to search for the text in the listview, the thing is as you can see it is going to select the last value that has that text, what I want is stop at the first one and be able by pressing the button again to select the next line that has the text Private Sub CmdBgtSearchLOBJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdBgtSearchLOBJ.Click For Each lv In LstBgtLOBJ.Items 'Check if the description is in the list If TxtBgtLOBGJDescription.Text.CompareTo("") = 1 Then If lv.SubItems(1).Text.ToLower.IndexOf(TxtBgtLOBGJDescription.Text.ToLower) >= 0 Then lv.Selected = True LstBgtLOBJ.Items(lv.Index).Selected = True LstBgtLOBJ.EnsureVisible(lv.Index) LstBgtLOBJ.Focus() End If Exit For End If Next End Sub Quote
Nick_Net2004 Posted June 2, 2004 Author Posted June 2, 2004 It is ok now i used a temp value for the search text and a value to know where I am in the search list Quote
AlexCode Posted June 3, 2004 Posted June 3, 2004 I think you're trying to re-invent the wheel but as cube... :p How much time did you spent writing and testing that code? ;) If you did use that same time to learn RegEx, it would: - Be extremelly easy to do (in your present case). - Astronomically faster, even returning all results at once. - If, later on, you need to change something on that code you wouldn't need to stop thinking "What in hell is this 'TxtBgtLOBGJDescription.Text.CompareTo("") = 1' here for?". Don't get me wrong, but VB devellopers (as myself) usually tend to complicate the code, discarding the new/easyer/faster techs... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.