[英]Check two words to see if the beginning of word a is equal to word b
Given the following strings 给定以下字符串
String a = "hello";
String b = "hell";
String c = "help";
I would like to find out if string b is a substring of a, and if string c is a substring of a. 我想找出字符串b是否是a的子字符串,以及字符串c是否是a的子字符串。
You can see here the answer is clearly yes for b and no for c. 您可以在此处看到答案显然是b是,否是c。 How can I perform this test in Java?
如何用Java执行此测试?
很简单:
if (a.startsWith(b))
Try this: 尝试这个:
if(a.contains(b)) {...}
if(a.contains(c)) {...}
works also with: 适用于:
if(a.contains("ell")) {...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.