Hi All,
1. This is my string
"The description of the problem ERIndia_Bharti / 2/19/2008 8:37:00 PM last
comment only ER_Kista / 2/19/2008 9:45:00 AM last comment only ER_Kista /
2/19/2008 9:45:59 AM last comment only ER_Kista / 2/19/2008 9:47:00 AM"
I want to extract all those dates in this(here count is 4) and wants to
change them in the format say 2008-02-19T09:45:00(FOR 2/19/2008 9:45:00 AM
e.g.) and 2008-02-19T20:37:00Z(FOR 2/19/2008 8:37:00 PM) ,means 24 hours time
and then wants to store them in their postitions
like
"The description of the problem ERIndia_Bharti / 2008-02-19T20:37:00Z last
comment only ER_Kista / 2008-02-19T09:45:00Z last comment only ER_Kista /
2008-02-19T09:45:59 last comment only ER_Kista / 2008-02-19T09:47:00Z"
Where T and Z are just a aplphabet which needs to be concat.
How is this possible?This string has many dates like above in the sentence
but format will remian same(i.e. m/dd/yyyy h:mm:ss) so solution should be
general
Kindly help me
2. the other string wil be in the below format e.g. say
ER_Kista , 2/19/2008 9:47:50 PM
i want it to be printed as 2008-02-19T21:47:50Z
Where T and Z are just a aplphabet which needs to be concat.
Kindly assist me.
Thanks in advande for your work on this issue,
Deepak
Robbe Morris - [MVP] C# - 19 Feb 2008 14:51 GMT
I'm not a big regular expressions expert but this sounds like a
perfect job for it.
Type in ".net regex" in google for some basic samples. regexlib.com
might have the expression you are looking for.

Signature
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web apps
without IT programmers.
Free download: http://www.equalssolved.com/default.aspx
> Hi All,
>
[quoted text clipped - 36 lines]
> Thanks in advande for your work on this issue,
> Deepak
Jesse Houwing - 19 Feb 2008 15:42 GMT
Hello deepak,
As Robbe already pointed out Regex is the way to go here. Combine it with
a MatchEvaluator and you're all done. Currently I do not have time to work
out an example for you, but I'll probably get round to it somewhere tonight.
Jesse
> Hi All,
>
[quoted text clipped - 37 lines]
> Thanks in advande for your work on this issue,
> Deepak
--
Jesse Houwing
jesse.houwing at sogeti.nl
Jesse Houwing - 19 Feb 2008 22:57 GMT
Hello deepak,
> Hi All,
>
[quoted text clipped - 37 lines]
> Thanks in advande for your work on this issue,
> Deepak
The following code does the trick:
======
private static readonly Regex rx = new Regex("[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}
[0-9]{1,2}:[0-9]{2}:[0-9]{2} (AM|PM)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static string ReplaceDates(Match m)
{
DateTime date = DateTime.ParseExact(m.Value, "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
return date.ToString("s") + "Z";
}
string input = "The description of the problem ERIndia_Bharti / 12/19/2008
8:37:00 PM last comment only ER_Kista / 2/19/2008 9:45:00 AM last comment
only ER_Kista / 2/19/2008 10:45:59 AM last comment only ER_Kista / 2/19/2008
9:47:00 AM";
string output = rx.Replace(input, new MatchEvaluator(ReplaceDates));
======
The regex takes care of finding all occurances of a date/time string in your
original input text.
The MatchEvaluator is used to parse the dates (I used the exact format used
here to make sure it parses correctly).
Then I rewrote every match using the "s" for sortable datetime format. This
doesn't append the "Z" at the end (the u(niversal) format does that, but
that doesn't have the T in the middle). I appended that manually.
I think it solves both your issues, as the format is the same in both strings.
Am I correct?
If you still have any questions, please let me know.
--
Jesse Houwing
jesse.houwing at sogeti.nl
deepak - 20 Feb 2008 04:53 GMT
Hi Jesse,
May we change your code to VB.NET, i am facing soem problem durign changing
it to VB.NET.May you help ?
- Deepak
> Hello deepak,
>
[quoted text clipped - 78 lines]
> Jesse Houwing
> jesse.houwing at sogeti.nl