LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Remove characters from string

On Sat, 27 Jan 2007 08:46:04 GMT, Ken McLennan
wrote:

I have no clue when it comes to reg expressions, and don't even
know whether any such thing would be a useful technique in this
instance.


Here's a routine, using regular expressions, that will extract the Time and the
a or the p.

It works on your examples.

However, if there were a number preceding the time that was not a time, it
would have to be modified.

It will return the existing time string and, if present in the original, an "a"
or a "p".

If some of the entries in your data differ significantly from what you've
posted, small changes in the "regex" may be required.

------------------------------------------
Option Explicit

Sub TestTimeParser()
Dim T(4) As String
Dim i As Long
T(0) = "6"
T(1) = "6A"
T(2) = "11:41 on call"
T(3) = "6:00 am On Call"
T(4) = "6:00pm On Call"

Dim objRe As Object
Dim colMatches As Object
Const Pattern As String = "[0-9:]+(\s?[ap])?"

Set objRe = CreateObject("vbscript.regexp")
objRe.Global = True
objRe.Pattern = Pattern
objRe.ignorecase = True

For i = 0 To UBound(T)

If objRe.test(T(i)) = True Then
Set colMatches = objRe.Execute(T(i))
Debug.Print Replace(colMatches(0), " ", "")
End If

Next i

End Sub
----------------------------------------


--ron
 
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 do I remove unwanted characters within a text string. bill Excel Discussion (Misc queries) 2 February 6th 09 01:15 AM
Remove characters from string Niek Otten Excel Programming 12 January 29th 07 04:37 AM
Remove characters from string Helmut Weber[_2_] Excel Programming 2 January 28th 07 11:36 AM
Remove all characters following the first character in a string RC Excel Discussion (Misc queries) 5 August 30th 05 03:17 AM
Remove characters from a text string using a formula duncrbrt Excel Discussion (Misc queries) 1 June 4th 05 02:19 AM


All times are GMT +1. The time now is 08:33 AM.

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

About Us

"It's about Microsoft Excel"