Jump to content

remove ascii from .nfo


Recommended Posts

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:

Link to comment
Share on other sites

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

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?

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

$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
Link to comment
Share on other sites

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 :(

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...