我正在尝试编写一个函数来检查字符串的多个条件。但是,当我试图弄清楚如何检查字符串中的第一个字符是否仅为字母时,我遇到了困难。
User
"u__adced_123" 应该返回 true 但它返回 false。我试过 str[0]==onlyLetters 但还是一样。
答案 0 :(得分:1)
fun click(x: Int, y: Int) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
val path = Path()
path.moveTo(x.toFloat(), y.toFloat())
val builder = GestureDescription.Builder()
val gestureDescription = builder
.addStroke(GestureDescription.StrokeDescription(path, 10, 10))
.build()
println("Click : " + x + "," + y)
dispatchGesture(gestureDescription, null, null)
}
检查整个字符串。要获取第一个字符,请使用 onlyLetters.test(str)
。
str.charAt(0)
答案 1 :(得分:0)
const onlyLetters = /[a-zA-Z]/;
function SearchingChallenge(str) {
// code goes here
return (
str.length > 4 &&
str.length < 25 &&
onlyLetters.test(str[0])
);
}
console.log(SearchingChallenge('abcde'));
console.log(SearchingChallenge('1234'));
console.log(SearchingChallenge('bcdefghijklmnopqrstuvwxy'));