Sign in to follow this  
Followers 0
NSearch

Remove all single quotes from a DAT file

15 posts in this topic

Can anyone think of a way to remove all single quotes, along with some other characters from a DAT file without opening up the file and stripping characters from the string.

Thanks.

Share this post


Link to post
Share on other sites



FileDelete()

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

FileDelete() deletes a file. I would like to remove characters from within the file.

Share this post


Link to post
Share on other sites

As a DAT file can be almost anything that holds data, then your question is very extensive to answer. Is it a binary or file or a text file format?

You can also find a DAT file on a VCD that holds the mpeg information that plays the video and audio.

If this file is in plain ansi text format, then you should be able to use FileOpen(), read each line with FileReadLine() and then use StringReplace() to remove the single quotes. Then write it back to a file with FileWriteLine(). Use FileClose() to finish the task.

Note: This does mean opening the file and stripping from strings which is against your first post, but is rather impossible otherwise with doing it without.

Share this post


Link to post
Share on other sites

FileDelete()

8)

Ha... I sense an attempt at humor in that reply :P


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

It is an EDI file with no extension. Sorry for being so vague. When I open the file in notepad, it is plain text.

Share this post


Link to post
Share on other sites

The file sounds ok to edit.

You could avoid opening the original file by copying it to a temp place open, read, replace single quotes, write, close, then move it over to overwrite the original. That saves opening the original but you are still stripping strings.

Share this post


Link to post
Share on other sites

I have been searching for some batch files. I hope that I will be able to replace the characters this way rather than writing script to perform this action.

Share this post


Link to post
Share on other sites

maybe like this

#include <String.au3>

$C_Text_location = @ScriptDir & '\10-20-2005.txt'; place your file location here

clean_text( $C_Text_location)

Func clean_text( $C_Text_location)
    
    Local $Cfile, $Cchars
    
    $Cfile = FileOpen($C_Text_location, 0)
; Check if file opened for reading OK
    If $Cfile = -1 Then
        MsgBox(0, "Error", "Unable to open C list   " )
        Exit
    EndIf
    
; Read in 1 line at a time until the EOF is reached
    While 3
        $Cchars = FileReadLine($Cfile)
        If @error = -1 Then ExitLoop
        
        If StringInStr($Cchars,"'") then StringReplace($Cchars,"'","")
        If StringInStr($Cchars,"'") then StringReplace($Cchars,"'",""); place other charaters here - add more as needed
        
        FileWrite("C:\Temp\test.txt", $Cchars)
        
    Wend
    FileClose($Cfile)
    
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Or maybe like this:

$text = FileRead("c:\temp\test.txt", FileGetSize("c:\temp\test.txt"))
FileOpen("c:\temp\test.txt", 2)
FileWrite("c:\temp\test.txt", StringReplace($text,"'",""))
...you can add the extra code for error checking and file closing if you wish.

EDIT: You did say, "...remove all single quotes, along with some other characters..."

$text = FileRead("c:\temp\test.txt", FileGetSize("c:\temp\test.txt"))
$text = StringReplace($text,"'","")
$text = StringReplace($text,"/","")
$text = StringReplace($text,"\","")
FileOpen("c:\temp\test.txt", 2)
FileWrite("c:\temp\test.txt", $text)
...or you could learn about "Regular Expressions"... I've not.

@Valuater,

FileDelete()

Humor or just the only correct answer given this stipulation from the OP, "...without opening up the file..."?

:-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

>PLato

FileDelete()

Humor or just the only correct answer given this stipulation from the OP, "...without opening up the file..."?

:-)

>SmOke_N

Ha... I sense an attempt at humor in that reply wink.gif

yes.... both answers are correct

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

If StringInStr($Cchars,"'") then StringReplace($Cchars,"'","")
        If StringInStr($Cchars,"'") then StringReplace($Cchars,"'",""); place other charaters here - add more as needed

8)

Sorry to hijack this thread slightly, but why is it you can use an If-Then statement here and get away without using an EndIf? Is there somewhere in the Help File I can read more on this?

Cheers

Share this post


Link to post
Share on other sites

If...Then

--------------------------------------------------------------------------------

Conditionally run a single statement.

If <expression> Then statement

Parameters

expression If the expression is true, the statement is executed.

Remarks

This version of the If statement is used to execute a single statement without the overhead of an EndIf.

The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed.

Related

If...Else...EndIf, Select...Case...EndSelect

Example

;Terminates script if no command-line arguments

If $CmdLine[0] = 0 Then Exit

;Alternative:

If $CmdLine[0] = 0 Then

Exit

EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Sorry to hijack this thread slightly, but why is it you can use an If-Then statement here and get away without using an EndIf? Is there somewhere in the Help File I can read more on this?

Cheers

You only need "EndIfs" for multiline "If" statements.If it is a single line "If" (like the one you are asking about) then no "EndIf" is needed.

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Thanks Guys.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0