Sign in to follow this  
Followers 0
NSearch

Stripping TABs from a string

21 posts in this topic

Any ideas on how to strip TABs from a string?

Thanks,

Stephen

Share this post


Link to post
Share on other sites



Any ideas on how to strip TABs from a string?

Thanks,

Stephen

StringStripWS()

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Can you please post an example of the text file.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

File with problem, I would like to strip all little carriage returns (little rectangles) or whatever they are.

You will have to right click, and save target in order to see what I am talking about.

Thanks.

fedexinv_output.txt

Edited by NSearch

Share this post


Link to post
Share on other sites

These lines are the same:

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

What about ?:

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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 "".

Can you run this by me again ?

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

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

Share this post


Link to post
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).

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)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

think you need to do this:

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Nope, that didnt work either

Share this post


Link to post
Share on other sites

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)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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