将字符串分成等份(java / groovy) [英] Splitting a string into equals parts (java/groovy)
本文介绍了将字符串分成等份(java / groovy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将字符串拆分为具有20个字符(或更少的尾部)的子字符串。
I'd like to split the string into substrings which has 20 chars (or less for the tail). Is there some library or I need to make the class for that?
推荐答案
您应该使用:$ b $是否有一些库或我需要为此类创建类? b
you should use :
s.split("(?<=\\G.{20})");
\G
是一个零宽度断言匹配前一场比赛结束的位置。如果没有以前的匹配,则匹配输入的开头,与 \A
相同。封闭倒序与最后一场比赛结束时的20个字符相匹配。
\G
is a zero-width assertion that matches the position where the previous match ended. If there was no previous match, it matches the beginning of the input, the same as \A
. The enclosing lookbehind matches the position that's 20 characters along from the end of the last match.
这篇关于将字符串分成等份(java / groovy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文