如何检查给定的字符串是否包含另一个子字符串?
如何检查给定的字符串是否包含另一个子字符串?
fun isFieldRepeated(jsonIn: String, field:String): Boolean {
var count: Int = 0;
while (jsonIn.indexOf(field) > -1) {
jsonIn = jsonIn.substring(jsonIn.indexOf(field)+field.length(),jsonIn.length());
count++;
}
if(count>1)
return true;
return false;
}
How can I check whether a given string contains another substring more than once?
fun isFieldRepeated(jsonIn: String, field:String): Boolean {
var count: Int = 0;
while (jsonIn.indexOf(field) > -1) {
jsonIn = jsonIn.substring(jsonIn.indexOf(field)+field.length(),jsonIn.length());
count++;
}
if(count>1)
return true;
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会简化它
I would simplify it to
或作为扩展功能:
...例如,例如这样:
Or as an extension function:
... to be used for example like this: