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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding comma behind numbers in a text file?

Status
Not open for further replies.

realty205

Technical User
Aug 1, 2008
10
US
I am having difficulties in trying to add a comma behind a 6 digit number at the front of every line in a text file. Does anyone know of a good way to do it?

394923 3517 Redman Hall Rd, Pinson, AL Photo Added $28,900
394212 828 49th St, Birmingham, AL Price Changed $17,610
395814 818 85th St, Birmingham, AL Photo Added $21,900
400218 8300 Vassar Ave, Birmingham, AL New $22,777
399537 1023 N 48th St, Birmingham, AL Photo Added $35,500
400207 2312 33rd Ave, Birmingham, AL New $7,900
391464 21 N 2nd St, Birmingham, AL Price Changed $28,900
400039 1701 Cullom St, Birmingham, AL New $55,000
384939 701 W 4th Ct, Birmingham, AL Price Changed $14,000
400176 928 Woodward Rd, Midfield, AL New $35,700
400196 1835 19th St, Birmingham, AL New $39,900
396067 2533 20th St, Birmingham, AL Price Changed $42,000
 
One way perhaps...

strTemp = "394923 3517 Redman Hall Rd, Pinson, AL Photo Added $28,900"
WScript.Echo Left(strTemp, 6) & "," & Mid(strTemp, 7)

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
But wouldn't I need to iterate through each line of the text file?
 
Have a look at FileSystemObject

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Like PHV suggested and you will also look at the OpenTextFile Method

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I was actually able to do that part. I decided to go with pike characters so that I could differentiate the price comma from the others. I want to import this into excel.

In VB.Net I can do things like substrings. Is there anyway to pinpoint a specific character? I was thinking RIGHT() but don't see how to replace the specific character.
 
You may want to look at the following functions that might help you with strings

InStr
Mid
Right
Left

If you need a bit more power...you may consider using a Regular Expression

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Horrible right now but this did it:

Const ForReading = 1
Const ForWriting = 2

Dim info
Dim MLS
Dim editMLS
Dim Remainder
Dim final
Dim writeit
Dim strText
Dim price
Dim editPrice

'Create a File System Object
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim objfso
Set objfso = CreateObject("Scripting.FileSystemObject")

'Get the file contents
Dim MyFileContents
Set MyFileContents = fso_OpenTextFile("C:\Pristine.txt", ForReading, False)

Set objFiles = objFSO.OpenTextFile("C:\Final.txt", ForWriting)

Do While Not MyFileContents.AtEndOfStream


info = MyFileContents.ReadLine

MLS = left(info,7)

MLS = Trim(MLS)

editMLS = Replace(MLS,MLS, MLS & ",")

Remainder = Replace(info,MLS,"")

Remainder = LTrim(Remainder)

final = editMLS & Remainder

final = Replace(final,",","|")

price = Right(final,5)

final = Replace(final,price,"")

price = Replace(price,"|",",")

final = final & price

objFiles.Writeline final

Loop


objFiles.Close

'Cleanup
MyFileContents.Close
Set MyFileContents = Nothing
Set fso = Nothing


Set objFSOt = CreateObject("Scripting.FileSystemObject")
Set objFilet = objFSO.OpenTextFile("C:\final.txt", ForReading)

strText = objFilet.ReadAll
objFilet.Close

strNewText = Replace(strText, "New", "|")
strNewText = Replace(strNewText, "Photo Added", "|")
strNewText = Replace(strNewText, "Price Changed","|")
strNewText = Replace(strNewText, " |","|")
strNewText = Replace(strNewText, "| ","|")
strNewText = Replace(strNewText, " | ","|")

Set objFilet = objFSOt.OpenTextFile("C:\final.txt", ForWriting)
objFilet.WriteLine strNewText
objFilet.Close


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top