Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old October 9th 19, 11:13 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: May 2019
Posts: 63
Default 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

  #2   Report Post  
Old October 9th 19, 12:40 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2011
Posts: 3,727
Default 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
  #3   Report Post  
Old October 9th 19, 08:01 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: May 2019
Posts: 63
Default 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".
  #4   Report Post  
Old October 10th 19, 02:29 AM posted to microsoft.public.excel.programming
dpb dpb is offline
external usenet poster
 
First recorded activity by ExcelBanter: Jan 2018
Posts: 80
Default 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.

--





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find a text in a string without giving the position of the Sreekanth Excel Discussion (Misc queries) 2 April 15th 10 09:07 PM
Find Character Position in String SportsDave Excel Programming 6 May 21st 06 09:49 PM
find nth position of a string TUNGANA KURMA RAJU Excel Discussion (Misc queries) 6 October 18th 05 01:25 PM
find position of a number in a string fullers80 Excel Worksheet Functions 1 September 6th 05 03:47 PM
How find character position # in string from right end? Or how get range row num Ian Elliott[_3_] Excel Programming 1 December 17th 03 03:56 PM


All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017