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

Re: String Format by Robbe

Robbe
Tue Feb 19 08:51:37 CST 2008

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.

--
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




"deepak" <deepak@discussions.microsoft.com> wrote in message
news:2F127423-EAEE-4F73-AD00-0D42C1D2D952@microsoft.com...
> 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
>
>


Re: String Format by Jesse

Jesse
Tue Feb 19 09:42:00 CST 2008

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,
>
> 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
--
Jesse Houwing
jesse.houwing at sogeti.nl



Re: String Format by Jesse

Jesse
Tue Feb 19 16:57:59 CST 2008

Hello deepak,

> 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



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



Re: String Format by deepak

deepak
Tue Feb 19 22:53:01 CST 2008

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

"Jesse Houwing" wrote:

> Hello deepak,
>
> > 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
>
>
>
> 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
>
>
>