Jump to content

StringInStr


someone
 Share

Recommended Posts

I've been having some trouble with StringInStr; how do I return the entire text what I am using StringInStr to find? I have an array with a lot of location site codes, in a format like NY123(ABC Avenue). I am trying to search for the NY123(ABC Avenue) with the string of ABC. While StringInStr finds the first instance of ABC how do I return the entire NY123(ABC Avenue)?

Also it seems stupid to turn an array into a string but if I use _ArraySearch($avArray, "abc") it wont' find anything. Does this mean I'm using _arraysearch wrong or something similar? ;)

Thanks in advance

If I'm being unclear or anything just let me know I feel a little :lmao: (I think I ate bad chinese food)....

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

I've been having some trouble with StringInStr; how do I return the entire text what I am using StringInStr to find? I have an array with a lot of location site codes, in a format like NY123(ABC Avenue). I am trying to search for the NY123(ABC Avenue) with the string of ABC. While StringInStr finds the first instance of ABC how do I return the entire NY123(ABC Avenue)?

Also it seems stupid to turn an array into a string but if I use _ArraySearch($avArray, "abc") it wont' find anything. Does this mean I'm using _arraysearch wrong or something similar? ;)

Thanks in advance

If I'm being unclear or anything just let me know I feel a little :lmao: (I think I ate bad chinese food)....

O.K. based on the information you provided: If you find the string "ABC" in an array element and the format is like you said, then the whole string is the content of the array element where you found the search string !??!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Cant you search for:

NY123(ABC Avenue)

?

No the problem is I'm making a script to copy info from one website into another. The 'parent' window will list a location simply as abc where as the 'child' website has them in a dropdown menu in the format NY123(ABC Avenue).

So I figured what makes the most sense is to create an array/or string out of the entire dropdown menu and search in that array/string for the text out of the 'parent' window (search for abc in NY123(ABC Avenue)) From there I am trying to send NY123(ABC Avenue) into the 'child' window. Make more sense?

Hey Kurt I'm sorry I didn't see your post.... I'm not sure I totally understand what you are saying.. sorry I'm still learning arrays.

If this post doesn't clear up what Im' trying to do let me know.

Edited by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

No the problem is I'm making a script to copy info from one website into another. The 'parent' window will list a location simply as abc where as the 'child' website has them in a dropdown menu in the format NY123(ABC Avenue).

So I figured what makes the most sense is to create an array/or string out of the entire dropdown menu and search in that array/string for the text out of the 'parent' window (search for abc in NY123(ABC Avenue)) From there I am trying to send NY123(ABC Avenue) into the 'child' window. Make more sense?

Hey Kurt I'm sorry I didn't see your post.... I'm not sure I totally understand what you are saying.. sorry I'm still learning arrays.

If this post doesn't clear up what Im' trying to do let me know.

What I'm saying is this. If your array content looks like this:

$array[1] = "NY123(ABC Ave.)"

$array[2] = "NY125(5th Ave.)"

$array[3] = "NY126(2nd Ave.)"

and you are searching for "ABC" with StringInStr() then, then whole string would be the content of $array[1], as that's the element where you found "ABC".

Maybe you should post some samples of your array content....

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

What I'm saying is this. If your array content looks like this:

$array[1] = "NY123(ABC Ave.)"

$array[2] = "NY125(5th Ave.)"

$array[3] = "NY126(2nd Ave.)"

and you are searching for "ABC" with StringInStr() then, then whole string would be the content of $array[1], as that's the element where you found "ABC".

Maybe you should post some samples of your array content....

Cheers

Kurt

Before I go much further here is what code I have

$oSelect = _IETagNameGetCollection($oIE, "select", 3)
$avArray = _ArrayCreate ("")
$oOptions = $oSelect.options
For $oOption in $oOptions
    _ArrayAdd($avArray, $oOption.text & @CR)
   ;ConsoleWrite($oOption.text & @CR)
 Next

$searchstring = StringInStr($avArray,"350")
$searcharray = _ArraySearch($avArray, "350")
MsgBox(0,"",$searchstring);or $searcharray

Here are some examples of my array copied off the console

01222(350 Main Street)

01888(500 Plum Street)

01555(216 Old Country Road)

02085(9000 Queens)

02089(10 Martine Avenue)

02334(700 Madison Avenue)

If I use StringinStr or _arraysearch I don't come up with any results. Only if I make the array a string using _arraytoString and then stringinStr do I come up anything. However when I use stringinstr it returns the first instance of the substring... which isn't what I want exactly

Edited by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

You posted your code while I played with this little sample:

Dim $array[4]
$array[1] = "NY123(ABC Ave.)"
$array[2] = "NY125(5th Ave.)"
$array[3] = "NY126(2nd Ave.)"

$ans = _SearchFor("ABC")

MsgBox(0,"",$ans)

Func _SearchFor($var)
    For $i = 1 to UBound($array) - 1
        If StringInStr($array[$i],$var) Then Return $array[$i]
    Next
EndFunc
see if you can make sense/use of it...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

If I use StringinStr or _arraysearch I don't come up with any results. Only if I make the array a string using _arraytoString and then stringinStr do I come up anything. However when I use stringinstr it returns the first instance of the substring... which isn't what I want exactly

O.K.

1.) StringInStr() does not search arrays, that's why its called StringInStr(ing) ;)

2.) _arraysearch is fine, but it finds only the first occurance (without further coding). Is that what

you want?

I would recommend to loop through the array and use StringInStr() to find every occurance of the search string.

$searchstring = "ABC"
for $n = 0 to Ubound($avArray) 
   if StringInStr($avArray[$n],$searchstring) then
          ConsoleWrite("Found search string in: " & $avArray[$n])
   endif 
next

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Thanks a lot for your help, the codes you provided did what I was looking for. For whatever reason though using arraysearch didn't come up with any resutls which is why I turned to StringInstr.. not sure what I was doing wrong...

How would I use the second occurance of the string? If I use your code /dev it writes to the console all instances but is there a way to capture only the second or third occurance and assign is a var?

Thanks everyone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

Thanks a lot for your help, the codes you provided did what I was looking for. For whatever reason though using arraysearch didn't come up with any resutls which is why I turned to StringInstr.. not sure what I was doing wrong...

How would I use the second occurance of the string? If I use your code /dev it writes to the console all instances but is there a way to capture only the second or third occurance and assign is a var?

Thanks everyone

yep, just use a counter every time the string was found. Or write all occurance into a new array, then you can access the first, second, n-th occurance very easy ($new_array[$n] ; $n = 1,2,3,...)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...