On 8/15/2016 4:15 PM, Booth Martin wrote:
Methinks there is a better way than what I am doing.
Can you share what you are doing?
You can use code.midrange.com and paste the link here.
I have a string like "home/One/Two/sample.txt" and want to separate it
as two strings: "home/One/Two/" and "sample.txt". I will be doing this
in an .sqlrpgle program.
Suggestions on approach to this?
I'd love to launch into a sermon on the vagaries of different file
systems, but I think I'll wait for more info. For the problem as
stated, I'd start at the end and process toward the beginning.
If performance is the question you're asking, when I'm thinking about
performance, my thoughts tend in this direction:
1) Does the code do what I want?
2) Is the performance good enough?
3) Measure performance. Record conditions and results.
4) Optimise one thing based on measurements, and re-measure.
5) After enough iterations, use table of conditions and results to
determine 'best' algorithm.
The test jig should handle as many edge cases as you can imagine, and
then ask a 4 year-old for a few more. Zero length, greater than
'maximum', no delimiters in a 'full' string, no extension in a 'full'
string. A string with multiple dots (/dir.one/dir.two/file.txt). A
string with a really long extension
(/file.some_idiot_renamed_this_file_in_order_to_keep_windows_from_finding_it_cfg)
and a file with a really short one (file.1) Strings with various
punctuation marks and most importantly, strings with non-ASCII
characters (/Zoë/documents/résumé.docx). Popular character sets include
Latin, Korean, and Chinese. For extra credit, handle Arabic and Hebrew
and other right to left languages.
That's probably better than what most people do.
As an Amazon Associate we earn from qualifying purchases.