Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text file Manipulation

Status
Not open for further replies.

alspoll

Technical User
Joined
Feb 4, 2006
Messages
6
Location
US
Hello all,

I have been searching these threads for a script to format a names list i have in a text file. The names are formatted as

Last Name, First Name

What I wold like is

First Name Last Name

I found this script on another forum and tried to adapt it to my situation to no avail:

Dim FSO, objFile, RegEx, strDestin, strFile, strSource

Set FSO = CreateObject("Scripting.FileSystemObject")
Set RegEx = New RegExp

RegEx.Global = True
RegEx.Pattern = "^([^,]*), (.*)$"

Const ForReading = 1
strSource = "c:\testfile.txt"
strDestin = "c:\newfile.txt"

Set objFile = FSO.OpenTextFile(strSource, ForReading)
strFile = objFile.ReadAll
objFile.Close

strFile = RegEx.Replace(strFile, "$2 $1")

Set objFile = FSO.CreateTextFile(strDestin, True)
objFile.Write strFile
objFile.Close

Any help would be most appreciated.

TIA,
AL
 
[tt]
Set objFile = FSO.OpenTextFile(strSource, ForReading)
[blue]strFile=""
if not objFile.atendofstream then
strFile = objFile.ReadAll
end if[/blue]
objFile.Close

[blue]dim a
a=split(strFile,vbcrlf)
for i=0 to ubound(a)
a(i)=RegEx.Replace(a(i), "$2 $1")
next
[/blue]
Set objFile = FSO.CreateTextFile(strDestin, True)
[blue]objFile.Write join(a,vbcrlf)[/blue]
objFile.Close
[/tt]
 
Thank you VERY much for the quick reply...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top