这个是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[1] : p [2] }
原文:https://www.cnblogs.com/coding8832/p/14403389.html