10-26-2009 02:54 PM
I am having trouble with removing empty string lines from my final data output. I know it is simple to do, but I'm stuck in the same train of thought. The file is a converted hex file that is written to a series of records. Converted lines that result in all F's as the data need to be deleted and the # of records adjusted accordingly. I have the code to take the file, convert it, remove all records with F's, and adjust the # of records, but I'm left with a gap in my file that no matter my approach I cannot remove the empty string spaces consistently. I have attached the file with the spaces and the goal is to remove the spaces in between the blocks of code, and the spaces will not always be on the same lines. Thanks for any help. If needed I can attach the code I've already developed if needed.
Darrick
Solved! Go to Solution.
10-26-2009 03:39 PM
You could read the file line by line, and write it back out only if the length of the string <>0. (or perhaps <>1 in case the line feed character shows up in the string for an empty line.)
However, there is probably a way to modify whatever code you have now so that it doesn't write out the empty lines. Without seeing that code, it is hard to help.
10-26-2009 03:53 PM
10-26-2009 05:16 PM
It isn't pretty but here is a way. Note that it resizes an array in a loop which is generally a bad thing to do, but in this case it is only making the array smaller. The code is in 2009 (snipit sort of gives that away).
steve
10-27-2009 10:23 AM - edited 10-27-2009 10:26 AM
Or you could try :
This will replace anything or things you want and count the total number of replacements made
Since you only want to remove empty lines search for "\n\n" and replace with "\n"
10-27-2009 10:40 AM - edited 10-27-2009 10:41 AM
OOPS (should have tested that first) substitute the following :
Thanks for the confidence though!
10-27-2009 10:46 AM - edited 10-27-2009 10:55 AM
Thanks for the replies, any of these will work. I ended up reading line by line as Ravens Fan suggested.
Darrick