一个检索串提取代码示例是JAVA版本的,能不能用JS来写
这个是java版本的,能不能用js来写
public static String extractIndex(String encryptedData) {if (encryptedData == null || encryptedData.length() < 4) {
return null;
}
char sepInData = encryptedData.charAt(0);
if (encryptedData.charAt(encryptedData.length() - 2) != sepInDat a) {
return null;
}
String[] parts = StringUtils.split(encryptedData, sepInData);
if (sepInData == '$' || sepInData == '#') {
return parts[0];
} else {
return parts[1];
}
}
function extractIndex(s) {if (typeof s !== "string") return null
const l = s.length
if (l < 4) return null
const c = s[0]
if (s[l - 2] !== c) return null
const p = s.split(c)
return "$#".includes(c) ? p[0] : p [1]
}
回答
以上是 一个检索串提取代码示例是JAVA版本的,能不能用JS来写 的全部内容, 来源链接: www.h5w3.com/113482.html