![]() |
String manipulation
Greetings,
I have tried to write code to do this simple string manipulation, however, I have not been successful. I guess I am just looking at it wrong. An example string is Baby Blue 01/02/05 . 'Baby Blue' can be various words and also there can be more. What I need to do is strip away the date characters so I can change them. I can handle everything except stripping away the existing date characters. How is this programmed? Thanks in advance for your help!! |
String manipulation
Hi Ray,
See if this makes sense... '-------------------------------- Sub Test() Dim strText As String Dim strDate As String Dim lngN As Long strText = "Baby Blue 01/02/05" 'Find the first number For lngN = 1 To Len(strText) If Mid$(strText, lngN, 1) Like "#" Then strDate = Mid$(strText, lngN, 99) Exit For End If Next 'lngN 'do something to strDate if a number was found. If Len(strDate) Then strDate = "03/16/2005" ' Put it back together. strText = Left$(strText, lngN - 1) & strDate End If MsgBox strText End Sub '----------------------- Regards, Jim Cone San Francisco, USA "Ray Batig" wrote in message link.net... Greetings, I have tried to write code to do this simple string manipulation, however, I have not been successful. I guess I am just looking at it wrong. An example string is Baby Blue 01/02/05 . 'Baby Blue' can be various words and also there can be more. What I need to do is strip away the date characters so I can change them. I can handle everything except stripping away the existing date characters. How is this programmed? Thanks in advance for your help!! |
String manipulation
Function FindDate(ByVal TextIn As String) As String
Static regex As Object, matches As Object Dim x As Integer Dim sRet As String If regex Is Nothing Then Set regex = CreateObject("vbscript.regexp") regex.Pattern = "[0-9]{1,2}/[0-9]{1,2}/[0-9]{2,4}" regex.Global = True regex.ignorecase = True End If sRet = "" Set matches = regex.Execute(TextIn) If matches.Count 0 Then For x = 0 To matches.Count - 1 sRet = sRet & IIf(sRet = "", "", ",") & matches(x).Value Next x End If FindDate = sRet End Function -- Tim Williams Palo Alto, CA "Ray Batig" wrote in message link.net... Greetings, I have tried to write code to do this simple string manipulation, however, I have not been successful. I guess I am just looking at it wrong. An example string is Baby Blue 01/02/05 . 'Baby Blue' can be various words and also there can be more. What I need to do is strip away the date characters so I can change them. I can handle everything except stripping away the existing date characters. How is this programmed? Thanks in advance for your help!! |
All times are GMT +1. The time now is 01:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com