Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

function "substr"

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
pixelup
Smarty n00b


Joined: 11 Apr 2017
Posts: 4

PostPosted: Tue Apr 11, 2017 10:34 am    Post subject: function "substr" Reply with quote

Hello,
I encountered a problem with the "substr:" function.
I want to use this function to delete the last character of the string.
Here is how I write my variable:
Code:
{capture assign="loop_moderators"}
{foreach name=moderators from = $session.programme_moderators item=moderator}
{$moderateur.formatage_programme},
{/foreach}
{/capture}
{$loop_moderators|substr:0:-1}

When I test, the last character is not deleted ??
Would you see why it does not work?

Thank you for your help
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Apr 11, 2017 2:08 pm    Post subject: Reply with quote

{$loop_moderators|bin2hex}
{$loop_moderators|substr:0:-1|bin2hex}
Back to top
View user's profile Send private message
pixelup
Smarty n00b


Joined: 11 Apr 2017
Posts: 4

PostPosted: Wed Apr 12, 2017 9:07 am    Post subject: Reply with quote

Thank you for reply but it does not work !
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Apr 12, 2017 10:40 am    Post subject: Reply with quote

"It doesn't work" is a ridiculous statement. It conveys essentially no information.
Please state clearly, what you are doing, what results you expect, and what you actually observe.
Back to top
View user's profile Send private message
pixelup
Smarty n00b


Joined: 11 Apr 2017
Posts: 4

PostPosted: Wed Apr 12, 2017 12:36 pm    Post subject: Reply with quote

Ok sorry for that answer!
Here are more details:

Currently the result of this variable "{$ loop_moderators | substr: 0: -1}" is:
Quote:
P. Coulom (Toulouse / FRANCE), C. Silvain (Poitiers / FRANCE), P. Seksik (Paris / FRANCE)

The last character is not deleted because the last character is the "comma"

With your variable "{$ loop_moderators | bin2hex}" or "{$ loop_moderators | substr: 0: -1 | bin2hex}" here is the result:

Quote:
{$ Loop_moderators | bin2hex}
...292c0a090909090909090909

Quote:
{$loop_moderators|substr:0:-1|bin2hex}
...292c0a0909090909090909


To recall here is the loop that I use to display the data of my variable
Code:
{capture assign="loop_moderators"}
{foreach name=moderators from = $session.programme_moderators item=moderators}
{$moderateur.formatage_programme},
{/foreach}
{/capture}


Thanks
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Apr 12, 2017 3:26 pm    Post subject: Reply with quote

pixelup wrote:
Quote:
{$ Loop_moderators | bin2hex}
...292c0a090909090909090909

Quote:
{$loop_moderators|substr:0:-1|bin2hex}
...292c0a0909090909090909


Sooo... evidently, the code works as intended. It properly strips the last character off the provided string.
Your problem is that your source data is full of whitespaces. Either provide a clean source data, or change code logic to remove unnecessary whitespaces.
Back to top
View user's profile Send private message
pixelup
Smarty n00b


Joined: 11 Apr 2017
Posts: 4

PostPosted: Wed Apr 12, 2017 7:56 pm    Post subject: Reply with quote

Ok, thanks so much for your help!
I will examine more closely this history of space
And sorry for my english but I use google translate
thank you
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP