Do you want to compare str1 and str2. You could give this a try → String.compare() or String.contains() (if you know what parameters you are looking for.)
No, I want to skip {user_name} and {store_name} from this string "Hello {user_name}! Welcome to {store_name} How may I help you?" and then it will be "Hello ! Welcome to How may I help you?"
Now I want to compare "Hello ! Welcome to How may I help you?" with "Hello Awais Ali! Welcome To KHAADI How may I help you?" and get results TRUE.
Please try this
str1 = “Hello Awais Ali! Welcome To KHAADI How may I help you?”
str2 = “Hello {user_name}! Welcome to {store_name} How may I help you?”
in assign str2 = str2.Replace(" {user_name}“,”“).Replace(”{store_name}“,”")
str1.contains(str2)
If you want to compare the strings while ignoring the user name and store name, you need to use regular expression.
str1 = "Hello Awais Ali! Welcome To KHAADI How may I help you?"
strPattern = "Hello [\w ]+! Welcome to [\w ]+ How may I help you\?"
result = System.Text.RegularExpressions.Regex.IsMatch(str1, strPattern)
Hi! Sorry, I tested the pattern with a text with lower case t while your text has a capital T. Change the T to lower case or add the options IgnoreCase.
result = System.Text.RegularExpressions.Regex.IsMatch(str1, strPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Give me one more favor that how to match these two strings…
str1 = "Commerce BotE-commerce Website30 March at 19:34Tues 19:34You sent 30 March at 19:34Get StartedCommerce Bot sent 30 March at 19:34Hello Usman Ashraf! Welcome to KHAADI How may I help you? Commerce Bot sent 30 March at 19:34Would you like to check out the following items:Promotions 🎁Top Products 🏆Catalogue 📜You sent 30 March at 19:34restartCommerce Bot sent 30 March at 19:34Your conversation has been restarted.You sent 30 March at 19:34helloCommerce Bot sent 30 March at 19:34Hello Usman Ashraf! Welcome to KHAADI How may I help youCommerce Bot sent 30 March at 19:34Would you like to check out the following items:Promotions 🎁Top Products 🏆Catalogue 📜"
str2 = "Hello [\w ]+! Welcome to [\w ]+ How may I help you\?"
While in str1 Hello Usman Ashraf! Welcome to KHAADI How may I help you? is present.
With the Hello text, I mean the whole string “Hello …! Welcome to … How may I help you?”. Are you saying you want to match “Commerce BotE-commerce …” and all the other text too? Because that regular expression would not like pretty.