在Java中是否有一个通配符? [英] Is there such a thing as a wildcard character in Java?
问题描述
我正在运行一个比较程序,并且在一分钟它做一个直接的字符串到字符串的比较,如果他们是一个完全匹配,它输出,他们是一个匹配。
I'm running a comparison program and at the minute it does a direct 'string-to-string' comparison and if they are an exact match it outputs that they are a match.
好吧,我希望添加一个允许相似的附加功能...
Well, I was hoping to add an additional feature that allowed for 'similarity'...
例如:
String em1 = "52494646";
String em2 = "52400646";
if (em1.equals(em2)){
output.writeUTF(dir + filenames[i]);
}
这是一段代码。我想要它跳过00,仍然认为它是几乎相同的数字,仍然输出它。
This is sort of a snippet of the code. I'd like it so that it skips over the "00" and still recognises it as 'almost' the same number and still outputs it.
我想象它看起来像 String em2 =524+ ## +646
但这显然只是一个概念
I'd imagine it would look something like String em2 = "524"+ ## +"646"
but thats obviously just a concept
有人知道如果有一种方法有这种'通配符'(我从whi中选择了一个术语)或者有另一种方法来做这种相似性类型交易。
Does anyone know if there is a way to have this kind of 'wildcard' (a term I've picked up from uni SQL) or if there is another way to do this similarity type deal.
感谢:)
推荐答案
您可以使用正则表达式:
You can use regular expressions:
if (em1.matches("524[0-9]{2}646")) {
// do stuff
}
这篇关于在Java中是否有一个通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!