bob43 Posted January 12, 2007 Report Share Posted January 12, 2007 I am using Match Pattern to determine if a header is correct. I read the file in and search for the regular expression. The issue I am having is when I change the header by removing a character, when the header is rewritten as it is supposed to, but it decrements the next written character from the data. I want to only rewrite the information on the first line (header) and not have any other portion of the file affected. Quote Link to comment
Doon Posted January 12, 2007 Report Share Posted January 12, 2007 This sounds like it could be one of two things: a regex problem, or a file sizing issue (file re-sizing, to be specific). LV regular expressions are the bane of my existence (every once-in-a-while). If I could see your code, I might be able to help. -H Quote Link to comment
bob43 Posted January 12, 2007 Author Report Share Posted January 12, 2007 I have attached my code. any comments are welcome. thx bob Download File:post-6822-1168629164.vi Quote Link to comment
Mikkel Posted January 12, 2007 Report Share Posted January 12, 2007 I think a better solution is to modify the string already in memory (output from the 'Read Lines From File.vi') and rewrite the complete file. The way you are doing it now is bound to incorrectly overwrite data in the start of the file, leaving an incomplete dataset after the header. -Mikkel Quote Link to comment
bob43 Posted January 12, 2007 Author Report Share Posted January 12, 2007 I want to keep the data that follows the header, incorrect or not. I just want to rewrite the first line of the file. but thank you for you thoughts. bob Quote Link to comment
castech Posted January 13, 2007 Report Share Posted January 13, 2007 Hey Bob, From what I can see there are several issues here......... The string that you are comparing to has '\t' as text inserted in the string not the code '\t' indicating a tab. To correct this, right click on the regular expression constant and select 'codes display'. You will then see some extra '\' inserted. Remove these (i.e. make it look like it did when it wasn't in code display mode). The reason you are losing a character is that the text you are writing is longer than the text you are replacing. Remember that you are writing text from the start of the file regardless of how may characters were read. If you read 5 characters and wrote 10, you would replace the first 5 that you intended plus an extra 5 that you didn't want to overwrite. The only way around this is to read the text into memory after the matched string, append this to your new text and write it all out again.You can not just say 'replace the first line of text' because this requires other data in the file to be moved anyway. I agree with Mikkel, you have already read all of the text into memory so instead of using the match pattern icon, whjy not use the search and replace icon which will do the replace for you and then write out the whole text again. I have attached what I mean. Hope I have understood what you are trying to do! Cheers Download File:post-7495-1168703637.vi Quote Link to comment
bob43 Posted January 15, 2007 Author Report Share Posted January 15, 2007 Thanks Castech, I will definitely look this over. And thanks again Mikkel. You were both very helpful. bob Quote Link to comment
torekp Posted January 18, 2007 Report Share Posted January 18, 2007 If the above solutions are working for you, ignore the following advice. Some people on LAVA have recommended that when you write a file that has both header and data, you start the data at the Nth character where N is a nice round number large enough to cover any possible header you would want there. If you really want to get fancy, you can pre-write the file with blank header and data before your main code executes, to speed execution (reduce time wasted on file space allocation). Note, I haven't tried these tricks yet, but they sounded smart to me. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.