<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Vahid Taslimi's Web log (وبلاگ وحید تسلیمی) - .net-general</title><link>http://old.taslimi.me:80/Tags/.net-general</link><description>Vahid Taslimi's Web log (وبلاگ وحید تسلیمی) - .net-general</description><item><title>Invisible character when parsing DateTime</title><link>http://old.taslimi.me:80/invisible-character-when-parsing-datetime</link><description>&lt;p&gt;Today we faced a crazy situation. we have a piece of code in one of our applications which parses date and time value entered into a text box. Being lazy/smart developers we normally copy paste the sample value from the help file in order to test it. but crazy part was that when we copy paste it, .net could not parse the value throwing exception saying that the string was not in correct format. but if we typed exactly the same value it would work! aha let me copy paste both values into notepad and compare them char by char. ok they are exactly the same. &lt;/p&gt; &lt;p&gt;to cut the story short after spending some times on the issue we noticed that there is an invisible character at the beginning of the value copied from the help file. then we quickly created a console app to get the char code of the character. and yes that’s a valid unicode character with 8203 code called “&lt;a href="http://www.fileformat.info/info/unicode/char/200b/index.htm" target="_blank"&gt;Zero Width Space (U+200B)&lt;/a&gt;”.&lt;/p&gt; &lt;p&gt;having found the problem we could easily fix our help files and remove this character from them. &lt;/p&gt; &lt;p&gt;here is the small piece of code to remove the Zero Width Space character from a string.&lt;/p&gt; &lt;div id="codeSnippetWrapper"&gt; &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pattern = &lt;span style="color: #006080"&gt;@"\u200B"&lt;/span&gt;;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; Regex regex = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Regex(pattern);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; var matches = regex.Matches(content);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; Console.WriteLine(&lt;span style="color: #006080"&gt;"Found {0} Matches"&lt;/span&gt;, matches.Count);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; content = regex.Replace(content, &lt;span style="color: #006080"&gt;""&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Hope this saves you some time in future.&lt;/p&gt;</description><pubDate>Wed, 14 Mar 2012 21:56:08 GMT</pubDate><guid isPermaLink="true">http://old.taslimi.me:80/invisible-character-when-parsing-datetime</guid></item></channel></rss>