java字符串分隔符,在标记中保留分隔符 [英] java string delimiter, keeping delimiter in token

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

问题描述

我试图拆分一个字符串但是将分隔符保留在下一个标记的开头(如果可能的话)

im trying to split a string but keep the delimiter at the beginning of the next token (if thats possible)

示例:我正在尝试拆分字符串 F120LF120L into

Example: I'm trying to split the string F120LF120L into

F120
L
F120
L

我试过

StringTokenizer st = new StringTokenizer(str, "F,L");

但只返回

120
120


推荐答案

文档中,您可以使用 StringTokenizer st = new StringTokenizer(str,L,true); 最后一个参数是一个布尔值,指定也必须返回分隔符。

From the docs, you can use StringTokenizer st = new StringTokenizer(str, "L", true); The last parameter is a boolean that specifies that delimiters have to be returned too.

这篇关于java字符串分隔符,在标记中保留分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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