Solved

Removing all " from a log file!

Posted on 2003-12-03
6
232 Views
Last Modified: 2013-12-25
Hi experts,

I currently have a log file reading:-

"sdgfsbgkabfkadgba
"
"skdfskdgfsdngksfj
"
"dsfgsafdgedh
"
"dsfhgsdhsdgh
"
What i really want is a file without all the "s...ie some sort of TidyLog() routine which can b run after, does anyone have any ideas!

cheers matt
0
Comment
Question by:MattyAllen
6 Comments
 
LVL 10

Expert Comment

by:ADSaunders
ID: 9867492
Hi Matt
You've asked this before haven't you? Anyway, I noticed some errors in my previous solution, so try this one.

Public Sub TidyLog()
Dim strcontent As String
Dim ArrContent(1000) as string ' change to suit no of expected lines
dim i as integer, j as integer
Open strLogDestination For Input As #1
    i = 0
    Do Until EOF(1)
        Input #1, strcontent
        if trim(strcontent) = chr(34) then loop
        if mid(strcontent,1 ,1) = Chr(34) then strcontent = mid(strcontent, 2)
        ArrContent(i) = strcontent
        i = i + 1
    Loop
Close #1
Open strLogDestination For Output As #1
       for j = 0 to i - 1
           write #1, Arrcontent(j)
       next
Close #1
end sub

Make sure that the number of elements in the array is enough for all the expected (real) lines in the logfile

.. Alan


Regards .. Alan
0
 

Author Comment

by:MattyAllen
ID: 9867967
hi alan...

ye, iv asked this once wo guna put msg on other to ask u to cum on this q so cud get points coz got carried away and jst kept askin qs last time...neway...

i tried the code last time but it has a problem with this line and not really havin a clue wot im doin then i cant program my way round it...

if trim(strcontent) = chr(34) then loop

i think it has a problem with the loop part...well thats the bit that errors neway!

cheers matt
0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 9868340
This sub should do what you wish:

Private Sub FixLog(LogFileName As String)
    Dim MyInput As String
    Dim LgNumA As Integer
    Dim LgNumB As Integer
    Dim LogFileNameA As String
    LogFileNameA = Replace(LogFileName, ".", "A.") 'generates a new file name
    LgNumA = FreeFile
    Open LogFileName For Input As #LgNumA 'open old log
    LgNumB = FreeFile
    Open LogFileNameA For Output As #LgNumB 'open new log
    While Not EOF(LgNumA)
        Line Input #LgNumA, MyInput
        MyInput = Replace(MyInput, Chr(34), vbNullString) 'replace the character "
        Print #LgNumB, MyInput 'write to new log file
    Wend
    Close (LgNumA)
    Close (LgNumB)
    Kill LogFileName 'delete old log file
    Name LogFileNameA As LogFileName 'change the new log to the old log name
End Sub

HTH
dragontooth

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Accepted Solution

by:
Bob Learned earned 50 total points
ID: 9869478
Just food for thought:

Dim InputText As String

Open LogFileName For Input As #1
InputText = Input(1, Lof(1))
Close #1

InputText = Replace$(InputText, Chr$(34), "")

Open LogFileName For Output As #1
Print #1, InputText
Close #1


0
 
LVL 27

Expert Comment

by:Dabas
ID: 9871633
Hi MattyAllen,
TheLearnedOne beat me to the simplest answer!
Load the whole file into memory and remove all quote symbols with just one Replace statement.
This will not work if you have other quotes that are not at the beginning of the sentence and that you want to keep.

In that case you would have to replace all of the Carriage Return followed by a quote sequences with just a CR.

Dabas
0
 

Author Comment

by:MattyAllen
ID: 9873144
Hey people thanks for the responses...

Iv discovered a much easier solution so that is dealt with wen the log is written as oppose to edit it after...i found out that if u print a variable to a file the " " do not get printed wheras if u write it they do so i will use this, but thanks LearnedOne ur solution wud of worked i think!

cheers
matt
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question