Jump to content
Sign in to follow this  
Hadez

remove ascii from .nfo

Recommended Posts

Hadez

Im currently using this code to remove ascii from an nfo:

$fileList = ($nfoDirectory)
            $file = StringRegExpReplace(FileRead ($fileList),"[^0-9a-zA-Z \h\v]","")
            filewrite($StrippednfoLocation,$file)

It works ok, but i need it to keep The following characters .,[]\/ Im not too sure how to add exceptions. Anyone can point me in the right direction? thanks alot :idea:

Share this post


Link to post
Share on other sites
dantay9

Aren't you adding exceptions for everything you already have in there? Using [^0-9a-zA-Z .,\[\]\/ \h\v] should solve the problem unless I am missing something big.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
Hadez

ah c lol, that wud make sense lol. Thnaks mate :idea:

Share this post


Link to post
Share on other sites
Hadez

I seem to be having a slight issue with this. It strips the nfo fine, but when it writes the stripped nfo, it leaves a space where the ascii was instead of removing it. This ends up leaving massive spaces where the ascii used to be. Anyone got any idea how to solve this?

Share this post


Link to post
Share on other sites
Hadez

Damn. guess there isnt a way. i tried to have it so that there cant be 2 spaces in a row, but that completely ferked everything lol. Wanted to remove just the space where the ascii charater was. :idea:

Share this post


Link to post
Share on other sites
Spiff59

Do you want to left justify the lines you're keeping?

Do you want to maintain D O U B L E S P A C I N G and T__R__I__P__L__E_____S__P__A__C__I__N__G__?

Do you want to eliminate resulting blank lines?

You can do anything you want to do, in a dozen different ways.

Because of the odd variety found in .nfo files, you may find it difficult to achieve a perfect result.

Try sticking this after your StringRegExpReplace():

$file = StringRegExpReplace($file, Chr(13), Chr(255)) ; preserve carriage returns
 $file = StringStripWS($file, 7) ; strip leading, trailing, and repeated whitespace
 $file = StringRegExpReplace($file, Chr(255), Chr(13)) ; reinsert cr's

If you want to get much fancier than that (besides stripping blank lines), you'll need to process the file a line (or even character) at a time.

Edit: simulated triple spacing (to overcome extra spaces being edited out by BBS software)

Edited by Spiff59

Share this post


Link to post
Share on other sites
Hadez

Hey thanks for the response. I did what you said but it still has a massive white space at the top where the ascii used to be. The allign left worked good but the text starts midway down the page as the previous ascii was huge at the top. Im not sure how to go about removing the blank lines. Any ideas? It would be better to keep single blank lines but remove anything more than double blank lines. :idea: Thanks alot for responding mate :) Appreciate your time.

Share this post


Link to post
Share on other sites
Spiff59

Hey thanks for the response. I did what you said but it still has a massive white space at the top where the ascii used to be. The allign left worked good but the text starts midway down the page as the previous ascii was huge at the top. Im not sure how to go about removing the blank lines. Any ideas? It would be better to keep single blank lines but remove anything more than double blank lines. :idea: Thanks alot for responding mate :) Appreciate your time.

I like this (with the :punct: class) better than your original StringRegExp:

$file = StringRegExpReplace(FileRead ($fileList),"[^0-9a-zA-Z[:punct:]\h\v]","")
$file = StringRegExpReplace($file, Chr(13), Chr(255)) ; preserve carriage returns
$file = StringStripWS($file, 7) ; strip leading, trailing, and repeated whitespace
$file = StringRegExpReplace($file, Chr(255), Chr(13)) ; reinsert cr's

$file = StringRegExpReplace($file, "[\r\n][\r\n]*",@CRLF) ; remove blank lines

I'm no SRE expert and am having trouble figuring out how to leave just the first blank line.

Share this post


Link to post
Share on other sites
Hadez

That seems to work good. Thanks alot mate. Its weird as the stripped nfo is showing a white space at the top, but when i do a fileread() on it, it only selects the text, so the white space vanishes lol. Thanks alot for taking the time to help mate. Really appreciate it :idea:

Share this post


Link to post
Share on other sites
Spiff59

That seems to work good. Thanks alot mate. Its weird as the stripped nfo is showing a white space at the top, but when i do a fileread() on it, it only selects the text, so the white space vanishes lol. Thanks alot for taking the time to help mate. Really appreciate it :idea:

Just a last comment... I noticed that running through some of the .nfo's I have floating around that sometimes valid words are separated only with special characters. After processing they end up crammed together with no space between them... I think this works better:

$file = StringRegExpReplace(FileRead ($fileList),"[^0-9a-zA-Z[:punct:]\v]"," ")
Edited by Spiff59

Share this post


Link to post
Share on other sites
Hadez

$fileList = "D:\test1\Random.nfo"
$StrippednfoLocation = "D:\test2\Random.nfo"
$file = StringRegExpReplace(FileRead ($fileList),"[^0-9a-zA-Z[:punct:]\v]"," ")
$file = StringRegExpReplace($file, Chr(13), Chr(255)) ; preserve carriage returns
$file = StringStripWS($file, 7) ; strip leading, trailing, and repeated whitespace
$file = StringRegExpReplace($file, Chr(255), Chr(13)) ; reinsert cr's
$file = StringRegExpReplace($file, "[\r\n][\r\n]*",@CRLF) ; remove blank lines
filewrite($StrippednfoLocation,$file)

Im using this, but it keeps bunching stuff up. It doesnt keep the lines order that is in the original. Instead, it removes the spaces so it all groups together. Any ideas?

UPDATE: Ive tried loads of different combinations of the examples u gave here and it seems that the line

$file = StringStripWS($file, 7) ; strip leading, trailing, and repeated whitespace

seems to be the issue. It removes all of the spacing so the line order doesnt keep.

UPDATE 2: It seems the issue was the deleteing double spacing. I used

$file = StringStripWS($file, 3)

instead and, although it doesnt allign left, it still removes the giant spacing befroea dn after the body of text. Cheers for your help once again :idea:

Edited by Hadez

Share this post


Link to post
Share on other sites
Hadez

Ill keep searching for removing double line spacing :idea:

Share this post


Link to post
Share on other sites
Hadez

Sorted :idea: Found some stuff on this and combined it with some of your code.

$bar = StringRegExpReplace(FileRead ($fileList),"[^0-9a-zA-Z[:punct:]\v]"," ")
$bar = StringRegExpReplace($bar, "(?m)(\A\h+)|(^\h+)|(\h+$)|(\h+\z)|(\s+\z)", "") 
$bar = StringRegExpReplace($bar, " ", " ")                               
$bar = StringReplace($bar, @CRLF & @CRLF, @CRLF)                       
$bar = StringReplace($bar, @CR & @CR, @CR)                               
$bar = StringReplace($bar, @LF & @LF, @LF)
$bar = StringStripWS($bar, 3)
$bar = StringRegExpReplace($bar, "\v{3,}", @CRLF & @CRLF)

Seems to remove anything more than 1 line space, aswell as strip the ascii. :) Thanks again for everyones help :(

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.