![]() |
#1 |
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
![]()
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 '). |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,346
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
It is normal. All formatter functions return trimmed (in python, stripped) values.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
Quote:
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). |
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,346
Karma: 8012652
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. |
![]() |
![]() |
![]() |
#5 |
Zealot
![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,346
Karma: 8012652
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.
|
![]() |
![]() |
![]() |
#7 |
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
Ok, I understand. Thanks again for you help, chaley.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |