在长单词中添加n个字母后添加换行符 [英] Add line breaks after n numbers of letters in long words

查看:100
本文介绍了在长单词中添加n个字母后添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A有一个字符串,最长可达100个字符。是否有一种简单的方法可以在每10个字母的单词中插入换行符?例如:

A have a string that can reach up to 100 characters in lenght. Is there an easy way to insert line breaks in the word every 10th letter? For example:

aaaaaaaaaaaaaaaaaaaaaaaaa

应该转入

aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaa

我知道我可以使用html()方法修改html,但我不知道如何计算字符和插入标签。谢谢

I know that i can modify html with the html() method, but im not sure how to count characters and insert the tags. Thanks

推荐答案

这是一个选项:

string.match(/.{1,10}/g).join("<br/>");

这篇关于在长单词中添加n个字母后添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆