int (@NotNull CharSequence haystack, char needle, int from, int dx) { while (from >= 0 && from < haystack.length()) { final char currentChar = haystack.charAt(from); if (currentChar == needle) { return from; } else if (currentChar == '\n') { return -1; } from += dx; } return -1; }