Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What @danish is telling you is that you will need to try out RegEx (or regular expressions). There are tons of sites out there - <a href="http://msdn.microsoft.com/en-us/library/az24scfc%28v=VS.100%29.aspx" rel="nofollow noreferrer">MSDN</a>; <a href="http://weblogs.asp.net/rosherove/articles/6946.aspx" rel="nofollow noreferrer">Practical Parsing</a>; <a href="http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx" rel="nofollow noreferrer">Learn Regular Expressions</a> - just to name a few. </p> <p>If you are expecting your date in only 2 specific formats, then we only have 2 patterns that we would need to match. Your example data: </p> <blockquote> <p>FUTIDX 26FEB2009 NIFTY 0 -- There is date in the string.</p> <p>FUTIDX MINIFTY 30 Jul 2009 -- There is date in the string.</p> <p>FUTSTK ONGC 27 Mar 2008 -- There is date in the string.</p> </blockquote> <p>provides us with 2 patterns:</p> <ol> <li><code>ddMMMyyyy</code></li> <li><code>dd Mmm yyyy</code></li> </ol> <p>The example below will only look for a month in the short form. This should be enough to help you get going.</p> <pre><code>using System; using System.Text.RegularExpressions; namespace regexmonthtest { class MainClass { // in your class, define 2 string patterns static string pattern = @"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)"; public static void Main (string[] args) { Console.WriteLine (HasDate("FUTIDX 26FEB2009 NIFTY 0")); Console.WriteLine (HasDate("FUTSTK MINIFTY 30 Jul 2009")); Console.WriteLine (HasDate("FUTIDX 26api1234 NIFTY 0")); } public static bool HasDate (string textIn) { textIn = textIn.ToLower(); Console.Write(textIn + '\t'); return (Regex.Match(textIn, pattern).Success); } } } </code></pre> <p>output:</p> <blockquote> <p>futidx 26feb2009 nifty 0 True<br> futstk minifty 30 jul 2009 True<br> futidx 26api1234 nifty 0 False </p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload