Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

DateTime.ParseExact mit Wildcards

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Torsten Kraus - 10 Jul 2007 11:27 GMT
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
Torsten Kraus - 10 Jul 2007 11:33 GMT
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,
>
[quoted text clipped - 11 lines]
> danke & ciao
> Torsten
Peter Duniho - 10 Jul 2007 12:00 GMT
> 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
Torsten Kraus - 10 Jul 2007 12:17 GMT
Good idea. Thanks Pete!

ciao
Torsten

Peter Duniho schrieb:

>> How to parse "20071007abcd123100" when "abcd" can be any comination of
>> 4-Letters?
[quoted text clipped - 21 lines]
>
> Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.