how to compare two strings in java?(如何比较java中的两个字符串?)
问题描述
我有如下情况列表:字符串 A <-------> 字符串 B
我应该在以下条件下比较 A 和 B:
1-如果read中显示的数字两边不同,但其余数字相同,则表示A = B.
1- if number shown in read is different in both side but the rest is the same it means A = B.
2- 在某些情况下,例如 A 侧的第一个在红色显示的数字之后没有空格,但在 b 侧,在红色显示的数字和 X 之后有一个空格.
2- there is in some situation like the first one in A side after number shown in red there is not white space but in b side there is a white space after number shown in red and also after X.
3- 也有不同的情况,比如数字 3
3- there is also different cases like number 3
现在我怎样才能最好地比较这两个字符串?
private static void controlSimilarity(String memo,String ck,String bc,String id,String product) {
if(!id.equals(product)){
listIdentifier.add(new MmoCnBcIdProduct(memo,ck,bc,id,product));
}
推荐答案
我会尝试规范化"字符串.将两者都设为大写,将s+Xs+"替换为X",将s+%"替换为%",将s+MG"替换为MG"等,然后用空格或一些正则表达式将其分割(Scanner 类或 Guava 的 Splitter)并比较字符串的各个部分.
I'd try to "normalize" strings. Make both uppercase, replace "s+Xs+" with "X", replace "s+%" with "%", "s+MG" with "MG" etc., then split it by whitespaces or some regex (Scanner class or Guava's Splitter) and compare parts of the string.
这篇关于如何比较java中的两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何比较java中的两个字符串?


基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01