Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-05-2016, 03:17 AM
PRA007's Avatar
PRA007 PRA007 is offline How to find all string within string. Windows 7 64bit How to find all string within string. Office 2010 32bit
Competent Performer
How to find all string within string.
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

I want to make multiple regex find and replace in the rtf text so to extract some information. as I want to play with text and not the rtf as opened in word I am using fso.

This is the code sniplet:

Code:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, FileName, TextLine, Tempfile, inTempfile, strPath, Temp, intemp
FileName = "C:\Users\rahul\Desktop\PLR\1.rtf"
TempFile = "C:\Users\rahul\Desktop\PLR\Temp\1.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set inFile = fso.OpenTextFile(FileName)
Do While inFile.AtEndOfStream <> True
    TextLine = inFile.ReadAll
Loop
Set regEx_ = new regExp
With regEx_
    .Global = True
    .MultiLine = True
    .IgnoreCase = True
    .Pattern = "\{\\\w{4}\\\w{4}\\\w{11}"
TextLine = regEx_.replace(TextLine, "mmrk$&")
'many such find and replace to get IMP lines Having mmrk
End with
set Temp = fso.CreateTextFile(TempFile, True)
    Temp.Write TextLine
    Temp.Close
Set Temp = Nothing

Set intemp = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Users\rahul\Desktop\PLR\Temp\1.txt")
Set outFile = CreateObject("Scripting.FileSystemObject").CreateTextFile("C:\Users\rahul\Desktop\PLR\Temp\11.txt",True)

Do Until intemp.AtEndOfStream
    Dim line : line = intemp.Readline
    If Left(line, 4) = "mmrk" then outFile.writeLine(line)
Loop

intemp.Close
outFile.Close
inFile.Close
The problem is

If you see the code, You will notice that I am saving the string first as file and opening the same for reading again. Is there anyway we can extract lines containing specific string from string so as to avoid it saving.
Reply With Quote
 

Tags
vbscript, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find all string within string. Wildcard replace any string in context with a specified string wardw Word 7 05-07-2018 09:13 AM
How to find all string within string. How can I compare a string in a cell to another string? Amitti Word VBA 2 04-10-2017 07:35 PM
How to find all string within string. Why is this Find string not working TechEd Word VBA 5 07-05-2014 08:12 PM
How to find all string within string. Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
How to find all string within string. Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft