Solved

Removing all " from a log file!

Posted on 2003-12-03
6
229 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

832 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