![]() |
find text similar to yyyy-mm-dd in string
I'd like to find the location of each date within a very long string
(loaded to string from text file). The format of the dates is yyyy-mm-dd. It would be great if I could use "InStr" and "Like" together somehow, but I don't know how. Any ideas? Thanks. |
find text similar to yyyy-mm-dd in string
Try some code like the following:
Dim S As String Dim N As Long S = "asdf2006-12-05asdf" ' whatever For N = 1 To Len(S) - 10 If Mid(S, N, 10) Like "####-##-##" Then Debug.Print Mid(S, N, 10) Exit Sub End If Next N -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com wrote in message oups.com... I'd like to find the location of each date within a very long string (loaded to string from text file). The format of the dates is yyyy-mm-dd. It would be great if I could use "InStr" and "Like" together somehow, but I don't know how. Any ideas? Thanks. |
find text similar to yyyy-mm-dd in string
Change
For N = 1 To Len(S) - 10 to For N = 1 To Len(S) - 9 and remove the Exit Sub if your string can contain more than one date. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Chip Pearson" wrote in message ... Try some code like the following: Dim S As String Dim N As Long S = "asdf2006-12-05asdf" ' whatever For N = 1 To Len(S) - 10 If Mid(S, N, 10) Like "####-##-##" Then Debug.Print Mid(S, N, 10) Exit Sub End If Next N -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com wrote in message oups.com... I'd like to find the location of each date within a very long string (loaded to string from text file). The format of the dates is yyyy-mm-dd. It would be great if I could use "InStr" and "Like" together somehow, but I don't know how. Any ideas? Thanks. |
find text similar to yyyy-mm-dd in string
Thanks Chip. I guess I had just blocked that from my mind from the
start because I thought it would take forever with the length of the strings I'm working with. They're actually html files that I'm trying to manipulate & clickthrough. e.g. http://www.sec.gov/cgi-bin/browse-ed...company&CIK=ge |
find text similar to yyyy-mm-dd in string
The string comparison is quite fast, even with very long strings.
For example, even with a 32K string, S = Application.WorksheetFunction.Rept("A", 32000) & _ "asdf2006-12-05asdf2005-07-04" ' whatever the code I posted runs without visible pause. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com wrote in message oups.com... Thanks Chip. I guess I had just blocked that from my mind from the start because I thought it would take forever with the length of the strings I'm working with. They're actually html files that I'm trying to manipulate & clickthrough. e.g. http://www.sec.gov/cgi-bin/browse-ed...company&CIK=ge |
All times are GMT +1. The time now is 07:28 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com