Solved

Removing all " from a log file!

Posted on 2003-12-03
6
224 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now