Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert YYYY, MM, and DD as a single number string | Excel Discussion (Misc queries) | |||
Search, find or lookup defined text in text string | Excel Worksheet Functions | |||
Look for similar text and find the largest value and return value | Excel Discussion (Misc queries) | |||
can you find specific text in a string ignoring any other text | Excel Discussion (Misc queries) | |||
backwards find function to find character in a string of text | Excel Programming |