View Single Post
Old 09-11-2012, 03:04 AM   #10
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,361
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by unboggling View Post
I use this template for Saving Books to Disk:
Code:
{author_sort}/{title} - ({id})/{authors} - {series}{series_index:0>2s| | - }{title}
So to total characters of just the filename component of that path (not the folders), I would use this adaptation of the template provided by Man Eating Duck:

Code:
program:format_number(add(add(add(strlen(field('title')),strlen(field('authors'))),add(strlen(field('series')),strlen(field('series_index')))), 7), '{0:d}')
Excellent! I put a lot of work into template general program mode and it is nice to see people using it.

The following template will have significantly better performance and is (for me) easier to read. Like unboggling's template, it computes the length of the filename (the last component).
Code:
program: strlen(template('{authors} - {series}{series_index:0>2s| | - }{title}'))
This one computes the length of the entire path including the folders.
Code:
program: strlen(template('{author_sort}/{title} - ({id})/{authors} - {series}{series_index:0>2s| | - }{title}'))
And as long as I am in demonstration mode, the following will produce the same answer as the one provided by Man Eating Duck, but with better performance.
Code:
program: strlen(strcat(field('title'), field('author_sort')))
This works because "length(title) + length(author_sort)" equals "length(title concatenated with author_sort)". There is no need to use the format_number function in this case because what is desired is just the number. You would use format_number if you want embedded commas or the like.

Note that the strcat function can accept more than two arguments, so you can say something like
Code:
program: strlen(strcat(field('title'), field('author_sort'), field('series')))
chaley is offline   Reply With Quote