Java String Index Of indexOf(final String str, final String searchString)

Here you can find the source of indexOf(final String str, final String searchString)

Description

Helper method for getId(String).

License

Open Source License

Parameter

Parameter Description
str a parameter
searchString a parameter

Declaration

private static Integer[] indexOf(final String str, final String searchString) 

Method Source Code


//package com.java2s;
// ProjectForge is dual-licensed.

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from   w  w w.j  a  v a 2s  . co  m
     * Helper method for getId(String).
     * @param str
     * @param searchString
     * @return
     */
    private static Integer[] indexOf(final String str, final String searchString) {
        if (str == null || str.indexOf(searchString) < 0) {
            return null;
        }
        final List<Integer> list = new ArrayList<Integer>();
        int pos = -1;
        final int length = str.length();
        for (int i = 0; i < 100; i++) {
            // Endless loop detection
            if (pos >= length - 1) {
                break;
            }
            pos = str.indexOf(searchString, pos + 1);
            boolean syntax = true;
            if (pos >= 0) {
                // Check that a comma or [ bracket is left to the id=
                for (int j = pos - 1; j >= 0; j--) {
                    final char ch = str.charAt(j);
                    if (ch == ',' || ch == '[') {
                        break;
                    }
                    if (Character.isWhitespace(ch) == false) {
                        syntax = false;
                        break;
                    }
                }
                if (syntax == true) {
                    list.add(pos);
                }
            } else {
                break;
            }
        }
        final Integer[] result = new Integer[list.size()];
        return list.toArray(result);
    }
}

Related

  1. getPDFEncodingIndex(String key)
  2. getReplaceIndexes(String input, int startIndex, Stack replaceStack)
  3. getStructValue(String struct, int index)
  4. getTabIndexes(String text)
  5. getUserGroupsFromImpex( final String impexContent, final int uidIndex)
  6. indexOfClosingBracket(String text, int openingBracket)
  7. indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex)
  8. indexOfIgnoreCase(String str, String substring)
  9. indexOfMultiple(String line, char character, int count, int startIndex)