如何检查一个字符串是否以几个前缀之一开头? [英] How to check if a string starts with one of several prefixes?

查看:106
本文介绍了如何检查一个字符串是否以几个前缀之一开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ive得到以下if语句:

Ive got the following if statement:

String newStr4 = strr.split("2012")[0];
if(newStr4.startsWith("Mon"))
str4.add(newStr4);

我想要包括startsWith'星期一'星期二'Weds''Thrus''星期五'使用字符串时有一个简单的方法吗?我试过'||'但是没有工作...

I want it to include startsWith 'Mon' 'Tues' 'Weds' 'Thrus' 'Friday' etc. Is there a simple way to this when using strings? I tried '||' but it didn't work...

谢谢!

推荐答案

你的意思是:

if(newStr4.startsWith("Mon") || newStr4.startsWith("Tues") || ...)

或者您可以使用正则表达式:

or you could use regular expression:

if (newStr4.matches("(Mon|Tues|Wed|Thurs|Fri).*"))

这篇关于如何检查一个字符串是否以几个前缀之一开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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