Hi all,
Is there a way to find and remove multiple words in a string using linq?
For example i’d like to replace test1, test2 and test3 from the below from strTest if they appear
strTest = “This is a test1, test2 test to see if test3 words can be removed”
Thanks in advance
Yoichi
(Yoichi)
June 12, 2023, 11:02am
2
Hi,
I think we can achieve it using regex a the following.
System.Text.RegularExpressions.Regex.Replace(yourString,"\btest\d+\s*","")
Regards,
Thanks Yoichi, but the strings i’m looking to ignore could be ‘Dr’ or ‘Professor’ or teacher, etc. Is there anything that i can do to compare to a colleciton of strings & if any of those appear, remove?
Yoichi
(Yoichi)
June 12, 2023, 11:11am
4
How about the following expression?
keywords = {"Dr","Professor","teacher"}
Then
System.Text.RegularExpressions.Regex.Replace(yourString,"\b("+String.Join("|",keywords)+")\s*","",System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Regards,
1 Like
system
(system)
Closed
June 15, 2023, 11:22am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.