I have a program where I take a date from an RSS file and attempt to convert it into a DateTime. Unfortunately, the RSS file that I have to use has a lot of spacing issues. When I parse the string I get this:
"\t\t\n\t\t4/13/2011\n\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t"
I want to remove all of the \t‘s and\n‘s. So far these have all failed:
finalDateString.Trim('\t');
finalDateString.Trim('\n');
finalDateString.Trim();
finalDateString.Replace("\t", "");
finalDateString.Replace("\n", "");
finalDateString.Replace(" ", "");
Every one of the commands will return the same string. Any suggestions?
(I tagged RSS in the case that there is an RSS reason for this)
First, you can remove all the whitespace from your string by using a 1-character regular expression:
I just tested this, and it worked.
Second, I just tested calling
DateTime.Parse()on your string, and it worked without even removing the whitespace. So maybe you don’t even have to do that.