Solved

find a string pattern and then extract date from it

Posted on 2009-04-02
3
227 Views
Last Modified: 2013-11-25
if have a array of strings.
some of them look like:

test1
test2

but others look like
"2006-06 (jun)"
"2006-07 (jul)"

now i want to extract the date part from these strings (only the one's which contain the date, e.g. 2006-06) and convert (only the strings which look like they have date in them)  them to a "date time" format and store them in another array as "date time" items

how do i do it?

how


0
Comment
Question by:manivineet
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Avelan
ID: 24057143
Hey,
this should work.
Other solution is to use regex to extract the date but i'm not too familiar with it
so... ;)

-Avelan
MyStr = Split(str, " ")(0)
 
If IsDate(str) Then
   MyDate = Date.Parse(str)
   'Whatever else you need to do
Else
    'whatever
End If

Open in new window

0
 
LVL 4

Accepted Solution

by:
Avelan earned 500 total points
ID: 24057148
Whoops, a couple mistakes there but i'm sure you caught them anyhow :P
MyStr = Split(str, " ")(0)
 
If IsDate(MyStr) Then
   MyDate = Date.Parse(MyStr)
   'Whatever else you need to do
Else
    'whatever
End If

Open in new window

0
 
LVL 9

Expert Comment

by:Deathrace
ID: 24057703
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question