Java - 基于多个分隔符拆分字符串 [英] Java - Splitting String based on multiple delimiters

查看:35
本文介绍了Java - 基于多个分隔符拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想根据句子拆分一个字符串,因此(为了我正在做的事情),只要有 !, ., ?, :, ;.

I essentially want to split up a string based on the sentences, therefore (for the sake of what I'm doing), whenever there is a !, ., ?, :, ;.

如何使用多个项目来分割数组?

How would I achieve this with multiple items to split the array with?

谢谢!

推荐答案

String.split 需要一个正则表达式来拆分,所以你可以简单地:

String.split takes a regex to split on, so you can simply:

mystring.split("[!.?:;]");

这篇关于Java - 基于多个分隔符拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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