public static Iterator<String> splitOnCharacterAsIterator(String value, char needle, int count) {
        // skip leading and trailing needles
        int end = value.length() - 1;
        boolean skipStart = value.charAt(0) == needle;
        boolean skipEnd = value.charAt(end) == needle;
        if (skipStart && skipEnd) {
            value = value.substring(1, end);
            count = count - 2;
        } else if (skipStart) {
            value = value.substring(1);
            count = count - 1;
        } else if (skipEnd) {
            value = value.substring(0, end);
            count = count - 1;
        }

        final int size = count;
        final String text = value;

        return new Iterator<>() {
            int i;
            int pos;

            @Override
            public boolean hasNext() {
                return i < size;
            }

            @Override
            public String next() {
                if (i == size) {
                    throw new NoSuchElementException();
                }
                String answer;
                int end = text.indexOf(needle, pos);
                if (end != -1) {
                    answer = text.substring(pos, end);
                    pos = end + 1;
                } else {
                    answer = text.substring(pos);
                    // no more data
                    i = size;
                }
                return answer;
            }
        };
    }
@Test
    public void testSplitOnCharacterAsIterator() {
        Iterator<String> it = splitOnCharacterAsIterator("foo", ',', 1);
        assertEquals("foo", it.next());
        assertFalse(it.hasNext());

        it = splitOnCharacterAsIterator("foo,bar", ',', 2);
        assertEquals("foo", it.next());
        assertEquals("bar", it.next());
        assertFalse(it.hasNext());

        it = splitOnCharacterAsIterator("foo,bar,", ',', 3);
        assertEquals("foo", it.next());
        assertEquals("bar", it.next());
        assertFalse(it.hasNext());

        it = splitOnCharacterAsIterator(",foo,bar", ',', 3);
        assertEquals("foo", it.next());
        assertEquals("bar", it.next());
        assertFalse(it.hasNext());

        it = splitOnCharacterAsIterator(",foo,bar,", ',', 4);
        assertEquals("foo", it.next());
        assertEquals("bar", it.next());
        assertFalse(it.hasNext());

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 100; i++) {
            sb.append(i);
            sb.append(",");
        }
        String value = sb.toString();

        int count = StringHelper.countChar(value, ',') + 1;
        it = splitOnCharacterAsIterator(value, ',', count);
        for (int i = 0; i < 100; i++) {
            assertEquals(Integer.toString(i), it.next());
        }
        assertFalse(it.hasNext());
    }