Results 1 to 3 of 3

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

  1. #1
    Join Date
    Aug 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how do i check if any characters in an array appear within a string?

    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.

    Code:
    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:

    Code:
    myArray = Array("","","ş","ğ", "", "д", "ф")
    In other words, how do i check to see if any of the characters in myArray appears in myQuery?
    Thanks in advance.

  2. #2
    Join Date
    Mar 2021
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Following and same concern. Any new deets on this?

  3. #3
    Join Date
    Mar 2011
    Posts
    2,092
    Thanks
    59
    Thanked 111 Times in 108 Posts
    Blog Entries
    4

    Default

    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.

    Code:
    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.

Similar Threads

  1. Replies: 3
    Last Post: 01-09-2013, 02:34 PM
  2. Create string with random characters
    By borris83 in forum PHP
    Replies: 11
    Last Post: 03-31-2009, 07:05 PM
  3. Replies: 2
    Last Post: 02-03-2009, 10:45 PM
  4. Detect Characters in String
    By T Horton in forum JavaScript
    Replies: 1
    Last Post: 05-18-2008, 01:23 AM
  5. How to find certain characters in a string
    By Moranor in forum JavaScript
    Replies: 1
    Last Post: 02-09-2007, 10:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •