java indexOf找到aaa并用b替换

时间:2013-04-17 15:42:26

标签: java indexof

我正在尝试找到“aaa”的模式,并将其替换为“b”,例如使用indexOf,但它无法正常工作:

private boolean matchCase;
private boolean wholeWords;

private void containsSearchValue(String currentValue, List<MnvrFindContainer> foundList, String textToFind, int i, int j)
{

    if .....

    else if (matchCase && wholeWords && currentValue.contains(textToFind))
    {

        String s = currentValue;
        String pattern = textToFind;
        int index = 0;
        int lengthOfPattern = 0;
        do
        {
            index = s.indexOf(pattern, index + lengthOfPattern);
            lengthOfPattern = pattern.length();

            MnvrFindContainer fContainer = new MnvrFindContainer();
            fContainer.row = i;
            fContainer.column = j;
            foundList.add(fContainer);

        }
        while (index > -1);

    }          
}

0 个答案:

没有答案