How can i limit the number of charecters from a record i've got from the database. In php i'd use the function substr.
Thanks
| SitePoint Sponsor |

How can i limit the number of charecters from a record i've got from the database. In php i'd use the function substr.
Thanks




Code:the_string[0,the_number_of_characters]

Thanks![]()
For a "Rails" based solution there's also:
Code:truncate(0, string)
Eric A.
Founder and CEO, XMG Networks, Inc.
XMG Services: Web 2.0 Photo Management and Sharing | Web Hosting
Personal Blog: From Two 2 Twelve




And Rails magically knows how many characters you want![]()



You also want to look at validates_length_of (Model classmethod)
You'd be better using validation to assert a string is too big, and let the user fix it rather than randomly truncate a string unexpectantly to the user.
If validation is no worry, then yea, somestring[0, length] will do, or doing somestring[start..end] where start and end are integers will also work.
validation is really the way forward though imo for this
http://virtualfunction.net - Rails Web Development
http://squaremove.co.uk - Rails powered Property Listings
Bookmarks