Log in

View Full Version : how do i check if any characters in an array appear within a string?



rafael
04-21-2020, 01:07 AM
Hi

I currently have the ASP following code, where if a particular non-Latin character "д" appears in my search string, i get a desired response as below.


myQuery = request("myQuery")

If InStr(1, myQuery, "д", 1) > 0 then
Response.write "Query from languages ...... detected."
Else
Response.write "Continue searching English/Latin archive."
End if


But how do i replace my single character with an array of characters:


myArray = Array("ß","ü","ş","ğ", "ä", "д", "ф")

In other words, how do i check to see if any of the characters in myArray appears in myQuery?
Thanks in advance.

Justiin
03-17-2021, 07:40 AM
Following and same concern. Any new deets on this?

keyboard
03-18-2021, 12:10 AM
I don't use ASP, so bear with me and hopefully it works. I believe you're looking to see if a string is present in an array (using ASP Classic)?
There's no built in function (that I'm aware of) that does this, so you'll need to loop through the array and check against each.



Dim foundInArray
foundInArray = False

For Each el In myArray
If(InStr(myQuery, el) > 0) Then
foundInArray = True
Exit For
EndIf
Next

If foundInArray Then
Response.write "Query from languages ...... detected."
Else
Response.write "Continue searching English/Latin archive."
End if



While the above approach should work, it might not be the best option available. If you're looking to check if there's any characters that aren't in the Latin alphabet, this isn't the best way to do that.

On another note, this thread is attracting a lot of spam, so we'll be closing it shortly. If you have any further questions about the question, feel free to reply, or if it has already been locked, PM a moderator and we can reopen it.