Jump to content

Stripping TABs from a string


NSearch
 Share

Recommended Posts

or if u wanna keep spaces n such use

StringReplace($stringvariable, @TAB, '')

i think

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

I am looking at my output that was generated from grabbing from text from a MS Access window.

WinGetText("Microsoft Access")

I am saving the results to a text document, and I am getting these little rectangles in the output. (I believed them to be carriage returns or tabs).

I can not remove them using and the following statement:

$text = StringStripCR($text)
$text = StringReplace($text, @TAB, "")
$text = StringReplace($text, @CR, "")
$text = StringReplace($text, @CRLF, "")

Any help would be much appreciated.

Thanks.

Link to comment
Share on other sites

Can you please post an example of the text file.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

  • Developers

These lines are the same:

$text = StringStripCR($text)
$text = StringReplace($text, @CR, "")

What about ?:

$text = StringReplace($text, @LF, "")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Dangit.....I was just looking through the Macro reference guide, and saw that, and thought it was picked up in @crlf, guess I was wrong, because IT WORKS!

Thanks JdeB!

opened your file with a HEXeditor and it contains 0A0D0A and 0D0A0A character sequences so removing @CRLF will still leave a single 0A.... Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

If I wanted to remove all @lf from an entire file containing many of these characters, could I do it without opening the file?

This is a "contradiction in termino" :o

You will have to read the whole file , replace the @lf's and write it back to the same file.

here is one way of doing it in one line:

$filename = "????"
FileWrite($filename, StringReplace(FileRead($filename, FileGetSize($filename)), @LF, ''))
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I didn't see any rectangles :o but this cleans up the output file so I can read it, give it a try.

Note: you have to change the directory to wherever you have "fedexinv_output.txt" stored. Lemme know if this doesn't help, I'll try again.

$string = FileRead('C:\fedexinv_output.txt')
MsgBox(0,"",$string)
$string2 = StringRegExpReplace($string, "([^abcdefghijklmnopqrstuvwyzA-Z0-9.+]+)", @CR)
MsgBox(0,"",$string2)

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

I have the script working to replace @LF with "" (or nothing), but for some reason, it is adding in a droping the output down a line where I replace the @LF with "".

If StringInStr($File,@LF) Then 
            $File = StringReplace($File,@LF,"")
        EndIf
Link to comment
Share on other sites

  • Developers

I have the script working to replace @LF with "" (or nothing), but for some reason, it is adding in a droping the output down a line where I replace the @LF with "".

Can you run this by me again ?

Do you want to keep the @CRLF's and only replace the extra @LF's maybe ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

For testing, I took a @LF character and added it to a file, saved it, then tried to replace it with "" (nothing). But when I open the file after the program has finished instead of having the @LF character, the line jumps down to the next line (as if the enter key was hit).

Edited by NSearch
Link to comment
Share on other sites

  • Developers

For testing, I took a @LF character and added it to a file, saved it, then tried to replace it with "" (nothing). But when I open the file after the program has finished instead of having the @LF character, the line jumps down to the next line (as if the enter key was hit).

Did you check the input and the output file with an Hexeditor?

( that is really the only way to check the data, since different editors do different things with @cr and @lf's)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

$Cfile = FileOpen("C:\"&$file_name&"", 0)
    If $Cfile = -1 Then
        MsgBox(0, "Error", "" )
        Exit
    EndIf
    While 1
        $File = FileReadLine($Cfile)
        If @error = -1 Then ExitLoop
        If StringInStr($File,@LF) Then 
            $File = StringReplace($File,@LF,'')
        EndIf
        FileWrite("C:\"&$file_name&"2", $File & @CRLF)
    Wend

Link to comment
Share on other sites

  • Developers

think you need to do this:

;If StringInStr($File,@LF) Then 
            $File = StringReplace($File,@LF,'')
            $File = StringReplace($File,@CR,'')
       ;EndIf

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Nope, that didnt work either

The issue is that the sourse contains @crlf + @lf which is considered 2 lines.

this code replace the wrong combinations with @crlf

is this getting closer ?

$filename ="fedexinv_output.txt"
$filename2 ="fedexinv_output2.txt"
; read whole file
$wholeFile = FileRead($filename, FileGetSize($filename))
; Remove extra @LFs
$wholeFile = StringReplace($wholeFile, @LF, '')
$wholeFile = StringReplace($wholeFile, @CR , @CRLF)
FileWrite($filename2, $wholeFile)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...