troubleshooting Question

RegEx.Replace() not working like I want it to

Avatar of Sootah
SootahFlag for United States of America asked on
C#
4 Comments2 Solutions277 ViewsLast Modified:
I want to retain the case of the line that I'm checking for obscenities, but I can't get the regex.replace to do it's job. Right now I have to convert the line to lowercase and then remove the offending word that way. I want to leave the line as is but still remove the profanity.

How do I get RegEx.Replace() to replace what I want it to and leave the rest of the line alone case wise?

I don't want to have to test for
Crap
crap
CRAP
cRaP
etc

individually.


else //If the option to remove the whole line is unchecked then remove only the offending word
            {
                for (x = 0; x <= sArray.GetUpperBound(0); x++)
                {
                    for (y = 0; y <= sBadArray.GetUpperBound(0); y++)
                    {
                        if (sBadArray[y].ToString().Trim() != "" && sArray[x].ToString().ToLower().Contains(sBadArray[y].ToString().ToLower()))
                        {
                            sArray[x] = sArray[x].ToLower();
                            sArray[x] = sArray[x].ToString().Replace(sBadArray[y].ToString().ToLower().Trim(), "");
                            //Regex.Replace(sArray[x].ToString().ToLower(), sBadArray[y].ToString().ToLower().Trim(), "");
                            numBadWords += 1;
                        }
                    }
                    if (sArray[x].ToString().Trim() != "") sBuff.Append(sArray[x].ToString().Trim() + "\r\n");
                }
            }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros