短视频带货源码,对于输入的验证码,不区分大小写

短视频带货源码,对于输入的验证码,不区分大小写

适用于验证码校验(不区分大小写)

 

1
public class TestString {<br>    public static void main(String[] args) {<br>        testEquals("asd", "asd");<br>        testEquals("asD", "Asd");<br>    }<br>    /**<br>     * @see java.lang.String#equalsIgnoreCase<br>     * usage: checking vertification code<br>     */<br>    private static void testEquals(String a, String b) {<br>        System.out.println("\"" + a + "\".equals(\"" + b + "\") = " + a.equals(b));<br>        System.out.println("\"" + a + "\".equalsIgnoreCase(\"" + b + "\") = " + a.equalsIgnoreCase(b));<br>    }<br>}<br>class TestString {<br>    companion object {<br>        @JvmStatic<br>        fun main(args: Array<String>) {<br>            testEquals("asd", "asd")<br>            testEquals("asD", "Asd")<br>        }<br>        private fun testEquals(a: String, b: String) {<br>            println("\"$a\".equals(\"$b\") = " + (a == b))<br>            println("\"$a\".equalsIgnoreCase(\"$b\") = " + a.equals(b, ignoreCase = true))<br>        }<br>    }<br>}

​运行结果

 

1
"asd".equals("asd") = true<br>"asd".equalsIgnoreCase("asd") = true<br>"asD".equals("Asd") = false<br>"asD".equalsIgnoreCase("Asd") = true

源码

 

1
    public boolean equalsIgnoreCase(String anotherString) {<br>        return (this == anotherString) ? true<br>                : (anotherString != null)<br>                && (anotherString.value.length == value.length)<br>                && regionMatches(true, 0, anotherString, 0, value.length);<br>    }

1、优先判断内存地址值是否一致:this == anotherString

2、不为null且长度一致的情况下: regionMatches(true, 0, anotherString, 0, value.length)

 

1
<br>public boolean regionMatches(boolean ignoreCase, int toffset,<br>            String other, int ooffset, int len) {<br>        char ta[] = value;<br>        int to = toffset;<br>        char pa[] = other.value;<br>        int po = ooffset;<br>        // Note: toffset, ooffset, or len might be near -1>>>1.<br>//1、判断是否数组越界<br>        if ((ooffset < 0) || (toffset < 0)<br>                || (toffset > (long)value.length - len)<br>                || (ooffset > (long)other.value.length - len)) {<br>            return false;<br>        }<br>        //2、循环遍历char是否一致<br>        while (len-- > 0) {<br>            char c1 = ta[to++];<br>            char c2 = pa[po++];<br>            if (c1 == c2) {<br>                continue;<br>            }<br>            if (ignoreCase) {//是否忽略大小写,true 则同义转换为大写或同义转换为小写进行校验<br>                // If characters don't match but case may be ignored,<br>                // try converting both characters to uppercase.<br>                // If the results match, then the comparison scan should<br>                // continue.<br>                char u1 = Character.toUpperCase(c1);<br>                char u2 = Character.toUpperCase(c2);<br>                if (u1 == u2) {<br>                    continue;<br>                }<br>                // Unfortunately, conversion to uppercase does not work properly<br>                // for the Georgian alphabet, which has strange rules about case<br>                // conversion.  So we need to make one last check before<br>                // exiting.<br>                if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {<br>                    continue;<br>                }<br>            }<br>            return false;<br>        }<br>        return true;<br>    }

 

以上就是 短视频带货源码,对于输入的验证码,不区分大小写,更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(83)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示