简体   繁体   English

通过比较单词来比较字符串,只检查单词中相同数量的字母

[英]Compare strings by comparing words checking only the same number of letters in the word

Given:鉴于:

String s0 = "we wrocławiu"
String s1 = "w warszawie"

When:什么时候:

Collator collator = Collator.getInstance(new Locale("pl", "PL"));
collator.setStrength(Collator.PRIMARY);
collator.setDecomposition(Collator.FULL_DECOMPOSITION);
int result = collator.compare(s0, s1);

Then:然后:

assertTrue(result < 0);

But the result > 0.但结果 > 0。

How to compare strings to ignore the letter e ?如何比较字符串以忽略字母e So if it compares word with 3 letters to word with 5 letters it should only check 3 letters.因此,如果它将 3 个字母的单词与 5 个字母的单词进行比较,它应该只检查 3 个字母。

I would say:我会说:

Pseudo code:伪代码:

// Find the length of the string which has the smallest length

// Truncate the other string so that they have both the same lengths

// Compare them 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM