短视频带货源码,对于输入的验证码,不区分大小写
2022/4/13 17:12:43
本文主要是介绍短视频带货源码,对于输入的验证码,不区分大小写,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
短视频带货源码,对于输入的验证码,不区分大小写
适用于验证码校验(不区分大小写)
public class TestString { public static void main(String[] args) { testEquals("asd", "asd"); testEquals("asD", "Asd"); } /** * @see java.lang.String#equalsIgnoreCase * usage: checking vertification code */ private static void testEquals(String a, String b) { System.out.println("\"" + a + "\".equals(\"" + b + "\") = " + a.equals(b)); System.out.println("\"" + a + "\".equalsIgnoreCase(\"" + b + "\") = " + a.equalsIgnoreCase(b)); } } class TestString { companion object { @JvmStatic fun main(args: Array<String>) { testEquals("asd", "asd") testEquals("asD", "Asd") } private fun testEquals(a: String, b: String) { println("\"$a\".equals(\"$b\") = " + (a == b)) println("\"$a\".equalsIgnoreCase(\"$b\") = " + a.equals(b, ignoreCase = true)) } } }
运行结果
"asd".equals("asd") = true "asd".equalsIgnoreCase("asd") = true "asD".equals("Asd") = false "asD".equalsIgnoreCase("Asd") = true
源码
public boolean equalsIgnoreCase(String anotherString) { return (this == anotherString) ? true : (anotherString != null) && (anotherString.value.length == value.length) && regionMatches(true, 0, anotherString, 0, value.length); }
1、优先判断内存地址值是否一致:this == anotherString
2、不为null且长度一致的情况下: regionMatches(true, 0, anotherString, 0, value.length)
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) { char ta[] = value; int to = toffset; char pa[] = other.value; int po = ooffset; // Note: toffset, ooffset, or len might be near -1>>>1. //1、判断是否数组越界 if ((ooffset < 0) || (toffset < 0) || (toffset > (long)value.length - len) || (ooffset > (long)other.value.length - len)) { return false; } //2、循环遍历char是否一致 while (len-- > 0) { char c1 = ta[to++]; char c2 = pa[po++]; if (c1 == c2) { continue; } if (ignoreCase) {//是否忽略大小写,true 则同义转换为大写或同义转换为小写进行校验 // If characters don't match but case may be ignored, // try converting both characters to uppercase. // If the results match, then the comparison scan should // continue. char u1 = Character.toUpperCase(c1); char u2 = Character.toUpperCase(c2); if (u1 == u2) { continue; } // Unfortunately, conversion to uppercase does not work properly // for the Georgian alphabet, which has strange rules about case // conversion. So we need to make one last check before // exiting. if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) { continue; } } return false; } return true; }
以上就是 短视频带货源码,对于输入的验证码,不区分大小写,更多内容欢迎关注之后的文章
这篇关于短视频带货源码,对于输入的验证码,不区分大小写的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?
- 2024-05-09企业src漏洞挖掘-有意思的命令执行
- 2024-05-08阿里云域名注册流程,分享给第一次购买域名的新手站长!