Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 08-14-2012, 01:53 AM   #1
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Exclamation substr function trim

I'm using substr function to create a string at "save to disk" template.

I use substr(raw_field('title'),0,40) and works fine.... but when the last character is a space, it disapears (it seems like it's doing a trim).

Maybe it's a bug, or this is normal?

For example, for the title 'This is a simple title example', substr(raw_field('title',0,12) returns 'This is a si' (correct), but substr(raw_field('title',0,10) returns 'This is a' (and the correct is 'This is a ').
Pepin33 is offline   Reply With Quote
Old 08-14-2012, 04:07 AM   #2
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
It is normal. All formatter functions return trimmed (in python, stripped) values.
chaley is offline   Reply With Quote
Advert
Old 08-14-2012, 05:15 AM   #3
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Quote:
Originally Posted by chaley View Post
It is normal. All formatter functions return trimmed (in python, stripped) values.
Thanks, chaley.

Then, is there a way to get on a template the first 40 characters of title, even if the last one is a space? (I'm trying to replicate Calibre's directory struct, this is why I need first 40 characters from title).
Pepin33 is offline   Reply With Quote
Old 08-14-2012, 05:24 AM   #4
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The best way I can think of to do this is to build a custom template function that builds exactly the string you want. The formatter will still strip the results of this function, but I don't think that anything will remove embedded spaces.

Looking at the code, I see that substr does not in fact strip the results. What is doing that is the template result. This tells me that you can solve this problem using general program mode, constructing the components one by one and then strcat'ing them together.
chaley is offline   Reply With Quote
Old 08-14-2012, 05:34 AM   #5
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Thanks for your help, chaley.

The full template I'm using is this:
program: strcat(sublist(field('author'),0,1,'&'), '/', substr(raw_field('title'),0,40), ' (', field('id'), ')','/', substr(raw_field('title'),0,40), ' - ', sublist(field('author'),0,1,'&'))

To replicate directory struct in Calibre. It is:
Author's name / Title (first 40 chars) - (Calibre id) / Title (f. 40 chars) - Author

But the title's last character is lost if it's an space when I substr it. ¿?

Last edited by Pepin33; 08-14-2012 at 05:39 AM.
Pepin33 is offline   Reply With Quote
Advert
Old 08-14-2012, 05:39 AM   #6
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Ahh, that template can generate multiple consecutive blanks. Save to disk converts any series of white space characters to one blank. There is no way around that.
chaley is offline   Reply With Quote
Old 08-14-2012, 05:45 AM   #7
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Ok, I understand. Thanks again for you help, chaley.
Pepin33 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trim pictures bobopiet Library Management 1 05-27-2011 03:00 PM
Request Mute Function Dr. T enTourage Archive 4 11-10-2010 11:30 AM
Find function doug38 Ectaco jetBook 3 03-07-2010 10:51 PM
New MAP function? Wetdogeared Feedback 2 03-03-2010 08:11 AM
Need part # for a PRS-500 trim plate BobVA Sony Reader 2 01-02-2010 12:30 PM


All times are GMT -4. The time now is 06:39 AM.


MobileRead.com is a privately owned, operated and funded community.