将字符串拆分为字符串数组 [英] Split String into an array of String

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

问题描述

我正在尝试找到一种将String拆分为String数组的方法,例如,遇到白色香料时,我需要将其拆分

I'm trying to find a way to split a String into an array of String(s), and I need to split it whenever a white spice is encountered, example

我是保罗"

"hi i'm paul"

进入"

嗨"我"保罗"

"hi" "i'm" "paul"

如何使用RegularExpression在split()方法中表示空格?

How do you represent white spaces in split() method using RegularExpression?

推荐答案

您需要一个正则表达式,例如"\\s+",这意味着:在遇到至少一个空格时将其分割.完整的Java代码是:

You need a regular expression like "\\s+", which means: split whenever at least one whitespace is encountered. The full Java code is:

try {
    String[] splitArray = input.split("\\s+");
} catch (PatternSyntaxException ex) {
    // 
}

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

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