【问题标题】:How to choose the correct splitted string if it match the end of original String is it possible?如果它与原始字符串的结尾匹配,如何选择正确的拆分字符串?
【发布时间】:2017-08-05 18:24:59
【问题描述】:

我很难找到解决这个问题的方法:

// look we have two strings that have the same ending " day "
       String days[] = new String[] {"Sunday", "Monday"};
   // but here i want nday to be choosen for Monday
   // and day for Sonday
   String splDay[] = new String[] {"Mo","Sun","day","nday"};

现在会发生的是,endsWith 方法将选择“day”而不是“nday”

for (String splt: splDay)
{
    if (days[0].endsWith(splt))
    {
        //now it will pick
        Toast.makeText(this , splt , Toast.LENGTH_SHORT).show();
        break;
    }
}

请记住,我正在处理 1000 个拆分的单词,并且我想选择正确的单词来表示原始单词? 有可能吗?

【问题讨论】:

标签: java android logic words


【解决方案1】:

我不得不这样做:

String days[] = new String[] {"Sunday", "Monday"};

String splDay[] = new String[] {"Mo","Sun","day","nday"};

String AnswersArray[][] = new String[][]{  {"Sun","day"} ,{"Mo", "nday"}  };

这不是专业的方式,但我能做什么..这就是我所得到的。

【讨论】:

    猜你喜欢
    • 2023-01-24
    • 2023-02-10
    • 1970-01-01
    • 2017-02-15
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多