|
From: "Jon Paris" <Jon.Paris@Partner400.com> To: <rpg400-l@midrange.com> Cc: "Hans Boldt" <boldt@ca.ibm.com> Subject: convert this code Date: Mon, 22 Apr 2002 10:33:11 -0400 Reply-To: rpg400-l@midrange.com Jon wrote: > >> The best way to avoid problems is to just use the C run-time > >>function strtok_r() instead. >Thanks Hans - I hadn't seen that one - is it actually documented > anywhere? > >On a related topic, do you know the name of the strtok like >function that _doesn't_ ignore consecutive delimiters? strtok is >useless for parsing comma delimited files because of this. Hi Jon! Well, I wasn't the first person on that thread to mention strtok_r(). I really haven't found any really good documentation for strtok_r(). A Google search for "strtok_r manpage" turned up a couple of results, but they were primarily for strtok(). They don't really discuss how big to make the user-allocated buffer. I would assume at least as big as the first string argument. Regarding strtok() ignoring consecutive delimiters: Yikes, you're right! Even Python's string.split() method splits properly! I have no easy answers for that, but if you really want to use strtok(), it would appear that you have to replace all occurrances of ',,' in your strings with ', ,'. But in general, you really wouldn't want to use strtok() for CSV records anyways since strtok() doesn't handle CSV fields delimited by quotes. strtok(',') splits on commas whether or not the field is quoted. Cheers! Hans Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.