|
-
Sep 15th, 2008, 04:02 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Function to Check String Format and Replace with a Different Format
Hi guys,
I already search everywhere but I can't really find anything regarding this problem.
Let us say I have several strings in my word application in this format "11:59:00" (##:##:##). *Note is doesn't necessarily mean that there 'time'. It's just that they are written in that format.
What I what is to replace all instances of that string format into "11.59.00" (##.##.##). How do I do that?
I can see that I can work this through using the find functions wild cards of do it on vb code. But I really can't find any material that will help me on this matter. Thank you in advance.
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
Sep 15th, 2008, 05:55 AM
#2
Re: Function to Check String Format and Replace with a Different Format
You should just be able to use the vb Replace function, try this
vb Code:
Sub test() Dim aString As String testString = "11:59:00" testString = Replace(testString, ":", ".") Msgbox testString End Sub
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
Sep 15th, 2008, 06:11 AM
#3
Re: Function to Check String Format and Replace with a Different Format
Try this
Code:
Sub repwords()
Dim r As Range, i As Integer
Dim StringOld As String, StringNew As String
Set r = ActiveDocument.Range
For Each r In ActiveDocument.StoryRanges
For i = 1 To Len(r.Text)
If Mid(r.Text, i, 1) = ":" And Mid(r.Text, i + 3, 1) = ":" Then
StringOld = Mid(r.Text, i - 2, 8)
StringNew = Replace(StringOld, ":", ".")
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = StringOld
.Replacement.Text = StringNew
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If
Next i
Next r
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 21st, 2008, 09:29 PM
#4
Thread Starter
Addicted Member
Re: Function to Check String Format and Replace with a Different Format
Thank you very much. I got it.
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|