ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find position of date in string (https://www.excelbanter.com/excel-programming/454467-find-position-date-string.html)

RG III

Find position of date in string
 
I have the following variable:

str = "The video shows that on 9/24/2019 the suspect entered the store."

What's a good method for finding the position of the first date in a
string? In the above example, it starts at position 25.

Assume that my date formats will be "mddyyyy" or "mmddyyyy"

-Robert

Claus Busch

Find position of date in string
 
Hi Robert,

Am Wed, 9 Oct 2019 03:13:33 -0700 (PDT) schrieb RG III:

What's a good method for finding the position of the first date in a
string? In the above example, it starts at position 25.


try:

Const myStr = "The video shows that on 9/24/2019 the suspect entered the store."

i = InStr(myStr, "/")
myPos = InStrRev(myStr, " ", i) + 1


Regards
Claus B.
--
Windows10
Office 2016

RG III

Find position of date in string
 

Const myStr = "The video shows that on 9/24/2019 the suspect entered
the store."

i = InStr(myStr, "/")
myPos = InStrRev(myStr, " ", i) + 1



I suppose that works. It appears to just find the first "/" character
in a string, is that right?

And BTW, I made a typo in my above message. The format of the
dates is "m/dd/yyyy" or "mm/dd/yyyy".

dpb

Find position of date in string
 
On 10/9/2019 2:01 PM, RG III wrote:

Const myStr = "The video shows that on 9/24/2019 the suspect entered
the store."

i = InStr(myStr, "/")
myPos = InStrRev(myStr, " ", i) + 1



I suppose that works. It appears to just find the first "/" character
in a string, is that right?


Yes...not a very robust solution unless it can be assured the search
string doesn't have other instances of slashes besides.

And BTW, I made a typo in my above message. The format of the
dates is "m/dd/yyyy" or "mm/dd/yyyy".


You still have more work to do with the above even in the given case
depending upon whether is one- or two-digit month so you've got to
search back for the whitespace character before the characters before
the first slash to get the actual beginning of the string, the second
line in the above.

I dunno VBA well enuf to know otomh--is there a regular expressions
version of text search besides just simple string pattern matching? If
so, would be way to go.

--





All times are GMT +1. The time now is 05:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com