Solved

Removing all " from a log file!

Posted on 2003-12-03
6
222 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now