小编e_r*_*e_r的帖子

Ruby:子串到一定长度,也在子串中持续空格

我试图将一长串文本截断到一定长度,但也希望确保截断的结果在空格处结束.之后我还要附加一个省略号.

例如:

"This is a very long string that has more characters than I want in it."
Run Code Online (Sandbox Code Playgroud)

成为这个:

"This is a very long string that..."
Run Code Online (Sandbox Code Playgroud)

我从这开始,但显然这不涉及在空格上结束字符串的问题.

<%= item.description[0..30] %>&hellip;
Run Code Online (Sandbox Code Playgroud)

ruby string ruby-on-rails-4

33
推荐指数
3
解决办法
3万
查看次数

在PHP中将ASCII转换为纯文本

我正在抓取一些网站,并有ASCII文本,我想转换为纯文本存储在数据库中.比如我想要的

I have got to tell anyone who will listen that this is
one of THE best adventure movies I&#x27;ve ever seen.
It&#x27;s almost impossible to convey how pumped I am
now that I&#x27;ve seen it.
Run Code Online (Sandbox Code Playgroud)

转换成

I have got to tell anyone who will listen that this is
one of THE best adventure movies I've ever seen. It's
almost impossible to convey how pumped I am now that
I've seen it.
Run Code Online (Sandbox Code Playgroud)

我用手指搜索血腥,有什么帮助吗?

html php ascii plaintext

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

ascii ×1

html ×1

php ×1

plaintext ×1

ruby ×1

ruby-on-rails-4 ×1

string ×1