Solved

Removing all " from a log file!

Posted on 2003-12-03
6
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…

724 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