 |
 |

07-11-2004, 03:32 PM
|
 |
Centurion
|
|
Join Date: Mar 2004
Location: Cedarburg, WI, USA
Posts: 138
|
|
array searching
|
i have a string and an array of strings. I want to see if the array contains the string and if it does, get the index. I tried array.binarysearch(), but it always returns -2001 whether it exists or not.
|
|

07-11-2004, 03:59 PM
|
 |
Obsessive OPtimizer
Administrator * Guru *
|
|
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
|
|
|
Post a code snippet of how you're doing this.
|
__________________
Quis custodiet ipsos custodues.
|

07-11-2004, 05:17 PM
|
|
Newcomer
|
|
Join Date: Jul 2004
Posts: 17
|
|
The easy way would be...
Quote:
|
Originally Posted by davcaw
i have a string and an array of strings. I want to see if the array contains the string and if it does, get the index. I tried array.binarysearch(), but it always returns -2001 whether it exists or not.
|
This should get it done:
Dim txt As String
txt = "text to be found"
Dim txt_array(##) As String
'the array is filled up with desired data.
Dim i As Integer
For i = 0 To txt_array.Length - 1 ' length starts at 1, but indexing starts at 0
If txt = txt_array(i) Then
MsgBox(i)
End If
Next
|
|

07-11-2004, 06:58 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
To use BinarySearch, you have to Sort it first.
Array.Sort(xyz)
Res = Array.BinarySearch(xyz, "h")
something like this.
|
|

07-12-2004, 12:33 PM
|
 |
Centurion
|
|
Join Date: Mar 2004
Location: Cedarburg, WI, USA
Posts: 138
|
|
well, i ran in to another problem. The reason it wasn't working was because the string had a "p" on the end that was not supposed to be there. It seems that when i use the remove function, it removes the letters i tell it to, but then it adds a letter "p" to the end 
|
|

07-12-2004, 12:49 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
And what line does this occur on?
It must be something that you are accidentally assigning. You should be able to check by adding a few messagebox.Show statements. 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|