Hadez Posted May 2, 2010 Posted May 2, 2010 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
dantay9 Posted May 3, 2010 Posted May 3, 2010 (edited) 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 May 3, 2010 by dantay9
Hadez Posted May 5, 2010 Author Posted May 5, 2010 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?
Hadez Posted May 12, 2010 Author Posted May 12, 2010 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.
Spiff59 Posted May 12, 2010 Posted May 12, 2010 (edited) 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 May 12, 2010 by Spiff59
Hadez Posted May 12, 2010 Author Posted May 12, 2010 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. Thanks alot for responding mate Appreciate your time.
Spiff59 Posted May 12, 2010 Posted May 12, 2010 On 5/12/2010 at 1:50 PM, 'Hadez said: 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. 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.
Hadez Posted May 12, 2010 Author Posted May 12, 2010 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
Spiff59 Posted May 12, 2010 Posted May 12, 2010 (edited) On 5/12/2010 at 3:25 PM, 'Hadez said: 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 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 May 12, 2010 by Spiff59
Hadez Posted May 12, 2010 Author Posted May 12, 2010 (edited) $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 Edited May 12, 2010 by Hadez
Hadez Posted May 12, 2010 Author Posted May 12, 2010 Ill keep searching for removing double line spacing
Hadez Posted May 13, 2010 Author Posted May 13, 2010 Sorted 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now