Ajay Mavatkar

Ajay Mavatkar

  • NA
  • 68
  • 12.6k

find same words in string expression

Jun 5 2017 6:24 AM
I have a expression like as follows,
 
(Age = 20 and Age = 30 and Age = 40)
 
I want to convert the above expression as
 
Age IN (20,30,40)
 
Can any help? 

Answers (4)

1
Amit Gupta

Amit Gupta

  • 0
  • 22.9k
  • 242.5k
Jun 5 2017 12:28 PM
Use Replace function to generate your desired output
 
  1. string age ="(Age = 20 and Age = 30 and Age = 40)";  
  2. var value = "Age in" + age.Replace("Age","").Replace("=","").Trim().Replace("and",",").Trim();  
 
 Isnt simple?
Accepted Answer
0
Vivek Kumar

Vivek Kumar

  • 156
  • 11.8k
  • 5.6m
Jun 5 2017 8:43 AM
Are you using c#? Can you wite your sample code? 
0
Ajay Mavatkar

Ajay Mavatkar

  • 0
  • 68
  • 12.6k
Jun 5 2017 8:41 AM
Actually the string expression (Age = 20 and Age = 30 and Age = 40) needs to be converted to 
Age IN (20,30,40) to execute query. The above expression is stored in a string variable 
0
Vivek Kumar

Vivek Kumar

  • 156
  • 11.8k
  • 5.6m
Jun 5 2017 8:24 AM
 what do you want ? Can you elaborate your question?