C# WTF
Probably one of the funnier websites about coding and IT culture is The Daily WTF. There are always good stories that make you groan and laugh.
Well, I found my first WTF in a bit of random code I came across.
public string ReplaceForNewLineChar(string strInput)
{
int tmpCounter = 0;
string strTmp1 = "";
string strTmp2 = "";
tmpCounter = strInput.IndexOf("\\n");
if (tmpCounter == -1)
{
return strInput;
}
else
{
strTmp1 = strInput.Substring(0, tmpCounter);
strTmp2 = strInput.Substring(strTmp1.Length + 2,
strInput.Length - (tmpCounter + 2));
strTmp1 = strTmp1 + (char)10 + strTmp2;
return ReplaceForNewLineChar(strTmp1);
}
}
It’s a WTF, that’s for sure. We’ll just refactor that whole thing and replace it with a little ditty.
public string ReplaceForNewLineChar(string strInput)
{
return strInput.Replace("\n", "");
}
That’ll hold us over until I find and replace every call to this method with a call to the string replace method.