在索引处分割字符串 [英] split string at index

查看:143
本文介绍了在索引处分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在特定索引处拆分字符串?例如在索引10处分割字符串,使该字符串现在等于索引10之前的所有内容,然后转储其余部分.

How would I split a string at a particular index? e.g split string at index 10, making the string now equal to everything up to index 10 and then dumping the remainder.

推荐答案

substring(0,10)substring(0,11)取决于索引10是否应包含10?不过,您必须检查length() >= index.

What about substring(0,10) or substring(0,11) depending on whether index 10 should inclusive or not? You'd have to check for length() >= index though.

另一种选择是org.apache.commons.lang.StringUtils.substring("your string", 0, 10);

这篇关于在索引处分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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