Rails -- 中文字符串截取的函数
2015-11-11 14:21
706 查看
字符串截取
truncate("Once upon a time in a world far far away") # => "Once upon a time in a world..."
length是需要截取的字符串长度,包括中文和英文字符,如果不写,则有默认值,是28
truncate("And they found that many people were sleeping better.", :length => 25, :omission => '... (省略)') # => "And they f... (省略)"
omission是截取后末尾添加的字符结尾,默认是三个点的省略号。
如果字符串未达到指定长度,则不会发生变化。
简单示范一:
truncate("Once upon a time in a world far far away", :length=> 14) => Once upon a...
因为omission没有指定取值,所以默认为”…”,所以在字符串末尾加上”…”
单复数
pluralize(1, 'person') # => 1 person pluralize(2, 'person') # => 2 people pluralize(3, 'person', 'users') # => 3 users pluralize(0, 'person') # => 0 people
一般用于 view 层
原文链接:/article/9296263.html
相关文章推荐
- Rails--自动清除开发日志
- Mplayer 1.2 源码分析--main函数
- golang中container/ring包用法
- Timus Online Judge 1651 Shortest Subchain
- No Brainer
- U3D 平行光阴影细节 Directional Shadow Details
- golang中container/heap包用法
- HDU 2389 ——Rain on your Parade——————【Hopcroft-Karp求最大匹配、sqrt(n)*e复杂度】
- main()函数常用的格式:main(int argc,char **argv)
- Active UNIX domain Sockets--------由netstat想到的
- Foxmail 绑定企业邮箱
- LeetCode -- Container With Most Water
- 简单几步,在heroku中部署你的rails项目
- sleep join yield | wait notify notifyAll
- 访百度糯米之 Caused by: libcore.io.ErrnoException: open failed: EACCES (P
- tail /grep/more
- 解决Visual Studio 2015创建工程时的“DNX SDK version 'dnx-clr-win-x86.1.0.0-beta5' failed to install.”错误
- 【已解决】Activity MainActivity has leaked window PhoneWindow$DecorView@ that was originally added here
- CC2541 AirSync(3)——特征值
- hdu 4770 Lights Against Dudely(暴力+状压)