在 Scala 中,regionMatches 函数用于测试两个字符串区域是否相等。
boolean regionMatches(boolean ignoreCase, int toffset, String other, int offset, int len)
参数 | 描述 |
---|---|
ignoreCase | 是否忽略大小写 |
toffset | 开始索引 |
other | 要比较的字符串 |
offset | 要比较字符串的开始索引 |
len | 要比较的长度 |
如果匹配,则返回 true,否则,返回 false。
boolean regionMatches(int toffset, String other, int ooffset, int len)
参数 | 描述 |
---|---|
toffset | 开始索引 |
other | 要比较的字符串 |
ooffset | 要比较字符串的开始索引 |
len | 要比较的长度 |
如果匹配,则返回 true,否则,返回 false。
使用 regionMatches 函数,判断字符串是否区域相等
object HaiCoder {
def main(args: Array[String]) : Unit = {
println("嗨客网(www.haicoder.net)!\n")
var str1 = "Hello,HaiCoder!"
var str2 = "Hai,HaiCoder!"
var str3 = "Hai,haicoder!"
var match1 = str1.regionMatches(true, 6, str2, 4, 9)
var match2 = str1.regionMatches(true, 6, str3, 4, 9)
println("match1 =", match1, "match2 =", match2)
}
}
程序运行后,控制台输出如下:
我们使用了 regionMatches 函数可以判断两个字符串是否部分相等。
使用 regionMatches 函数,判断字符串是否部分相等
object HaiCoder {
def main(args: Array[String]) : Unit = {
println("嗨客网(www.haicoder.net)!\n")
var str1 = "Hello,HaiCoder!"
var str2 = "Hai,haicoder!"
var match1 = str1.regionMatches(6, str2, 4, 9)
println("match1 =", match1)
}
}
程序运行后,控制台输出如下:
我们使用了 regionMatches 函数判断两个字符串是否部分相等。
在 Scala 中,regionMatches 函数用于测试两个字符串区域是否相等。