The string I am trying to clean looks like
"\r\nPasswordchanged?\r\r\n" string
I used this method
public string[] cleanStrings(string[] clean)
{
int j = 0;
foreach (string data in clean)
{
string temp = System.Text.RegularExpressions.Regex.Replace(data, @"\r\n+", "");
if (temp.Equals(" "))
{
temp = "";
}
clean[j] = temp;
j++;
}
return clean;
}
The result was
"Passwordchanged?\r" string
I thought my regex would remove all the \r and \n
Did I miss something?
Use a character class instead, specifically
[\r\n]. This way any character in the character class will match.Your current pattern,
\r\n+, will only match an\rfollowed by one or more\ncharacters, so it won’t be able to match other stand-alone\rcharacters for example.