You can do this the very easy, yet error prone way of checking the index of the string apple in your comma separated list: var str = "ball, apple, mouse, kindle" var index = str.indexOf('apple') alert(index) Checking the result is >-1 tells you that the str contains the string apple.
To check if value exists in a comma separated list, you can use FIND_IN_SET () function. The syntax is as follows SELECT *FROM yourTablename WHERE FIND_IN_SET ('yourValue',yourColumnName) > 0; Let us first create a table.
How to match the exact string value in the list of comma separated string . kerthi Joe. Greenhorn Posts: 15. posted 4 years ago. I have List of array String , ... Joe Harry yes, I have to check whether the Info array values are in Compare_val. I have to iterate the Compare_val over the Info array and find what values are matching.
Check if inputted value exists in comma separated string with PHP December 15, 2015 PHP Trainer, Blogger, Teacher , Guru, Professional Trainer. mloshali The problem
Yesterday I needed to get all the dropdown values and create a comma separated list. One way to iterate through all dropdown elements and create string . But I found there is another way to achieve this. Use jQuery $.map() which applies a function to each item in an array or object and maps the results into a new array.
All-I am attempting to use a select statement in a stored procedure to check if a value in a comma separated string exists . The field to check against is defined in a select statement, and if we have a match, I would like to run the SQL.
If you want to know if there is more then one value in the comma separated string you could use the method that Avinash suggested (meaning the string "String1,String2,String1" contains 3 values ). If you would like to know if a specific string exists more then once in the comma separated string you could use something like this (quick and dirty):
A comma-separated string can be converted to an array by 2 approaches: Method 1: Using split() method The split() method is used to split a string on the basis of a separator. This separator could be defined as a comma to separate the string whenever a comma is encountered. This method returns an array of strings that are separated . Syntax:
FIND_IN_SET () function will match comma-separated values . It returns the position of a string value if it is available (as a substring) within a string . It returns 0 when the search string does not exist in the string . Syntax of this function is here: