Sootah
asked on
RegEx.Replace() not working like I want it to
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().T rim() != "" && sArray[x].ToString().ToLow er().Conta ins(sBadAr ray[y].ToS tring().To Lower()))
{
sArray[x] = sArray[x].ToLower();
sArray[x] = sArray[x].ToString().Repla ce(sBadArr ay[y].ToSt ring().ToL ower().Tri m(), "");
//Regex.Replace(sArray[x]. ToString() .ToLower() , sBadArray[y].ToString().To Lower().Tr im(), "");
numBadWords += 1;
}
}
if (sArray[x].ToString().Trim () != "") sBuff.Append(sArray[x].ToS tring().Tr im() + "\r\n");
}
}
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)
{
if (sBadArray[y].ToString().T
{
sArray[x] = sArray[x].ToLower();
sArray[x] = sArray[x].ToString().Repla
//Regex.Replace(sArray[x].
numBadWords += 1;
}
}
if (sArray[x].ToString().Trim
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
God. That's because I'm an idiot.
sArray[x] = Regex.Replace(sArray[x], sBadArray[y], "", RegexOptions.IgnoreCase);
I forgot the sArray[x] = part.
I'm going t go drown myself now. :)
G.I.G.O., eh?
sArray[x] = Regex.Replace(sArray[x], sBadArray[y], "", RegexOptions.IgnoreCase);
I forgot the sArray[x] = part.
I'm going t go drown myself now. :)
G.I.G.O., eh?
ASKER
Regex.Replace(sArray[x], sBadArray[y].Trim(), "", RegexOptions.IgnoreCase);
I cannot think of ANY reason this doesn't work. It pops up the messagebox at the end: "1 obscenity removed!" and yet the RegEx.Replace statement has done NOTHING. Why?