Hallo,

gibt es mit DateTime.ParseExact eine Möglichkeit Wildcards zu verwenden?

Beispiel:
"20071007abcd123100" soll geparst werden, wobei "abcd" beliebige andere
4 Zeichen seien können.

Ich denke also an so etwas wie:
DateTime.ParseExact("20071007abcd123100", "yyyyMMdd????HHmmss", null);

Hat da jemand eine Idee?

danke & ciao
Torsten

Re: DateTime.ParseExact mit Wildcards by Torsten

Torsten
Tue Jul 10 05:33:16 CDT 2007

Sorry for posing german. I selected the wrong group...
So here my question in english:

Is there any possibility to use wildcards with DateTime.ParseExact?

Sample:
How to parse "20071007abcd123100" when "abcd" can be any comination of
4-Letters?
Im looking for something like:
DateTime.ParseExact("20071007abcd123100", "yyyyMMdd????HHmmss", null);

any ideas?

best regards
Torsten


Torsten Kraus schrieb:
> Hallo,
>
> gibt es mit DateTime.ParseExact eine Möglichkeit Wildcards zu verwenden?
>
> Beispiel:
> "20071007abcd123100" soll geparst werden, wobei "abcd" beliebige andere
> 4 Zeichen seien können.
>
> Ich denke also an so etwas wie:
> DateTime.ParseExact("20071007abcd123100", "yyyyMMdd????HHmmss", null);
>
> Hat da jemand eine Idee?
>
> danke & ciao
> Torsten

Re: DateTime.ParseExact mit Wildcards by Peter

Peter
Tue Jul 10 06:00:59 CDT 2007

On Tue, 10 Jul 2007 03:33:16 -0700, Torsten Kraus <torsten.kraus@gmx.de>=
=

wrote:

> How to parse "20071007abcd123100" when "abcd" can be any comination of=
=

> 4-Letters?
> Im looking for something like:
> DateTime.ParseExact("20071007abcd123100", "yyyyMMdd????HHmmss", null);=

>
> any ideas?

Create a new string from the source string, with characters in wildcard =
=

positions replaced with some character (say, for example, '?'). Then in=
=

the string you provide to ParseExact(), use that replacement character i=
n =

the same position where you replaced them in the source string.

For example:

StringBuilder sb =3D new StringBuilder(strSource);

sb.Remove(8, 4);
sb.Insert(8, "????");

return DateTime.ParseExact(sb.ToString(), "yyyyMMdd????HHmmss", nul=
l);

For all I know, there is some better, approved wildcard mechanism that I=
=

obviously don't know about. But the above should work. :)

Pete

Re: DateTime.ParseExact mit Wildcards by Torsten

Torsten
Tue Jul 10 06:17:50 CDT 2007

Good idea. Thanks Pete!

ciao
Torsten

Peter Duniho schrieb:
> On Tue, 10 Jul 2007 03:33:16 -0700, Torsten Kraus <torsten.kraus@gmx.de>
> wrote:
>
>> How to parse "20071007abcd123100" when "abcd" can be any comination of
>> 4-Letters?
>> Im looking for something like:
>> DateTime.ParseExact("20071007abcd123100", "yyyyMMdd????HHmmss", null);
>>
>> any ideas?
>
> Create a new string from the source string, with characters in wildcard
> positions replaced with some character (say, for example, '?'). Then in
> the string you provide to ParseExact(), use that replacement character
> in the same position where you replaced them in the source string.
>
> For example:
>
> StringBuilder sb = new StringBuilder(strSource);
>
> sb.Remove(8, 4);
> sb.Insert(8, "????");
>
> return DateTime.ParseExact(sb.ToString(), "yyyyMMdd????HHmmss", null);
>
> For all I know, there is some better, approved wildcard mechanism that I
> obviously don't know about. But the above should work. :)
>
> Pete