Ruang penulis
← Kembali ke jurnal
Core API

How do I iterate a subset of a string?

package org.kodejava.text; import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class IterateSubstringExample { private static final String text = "How razorback-jumping frogs can level six piqued gymnasts"; public static void main(String[] args) { CharacterIterator it = new StringCharacterIterator(text, 4, 27, 5); // In this loop we just iterator a subset of character defined in the // StringCharacterIterator above. […]

DWayan · 11 Jan 2007 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

package org.kodejava.text;

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

public class IterateSubstringExample {
    private static final String text =
        "How razorback-jumping frogs can level six piqued gymnasts";

    public static void main(String[] args) {
        CharacterIterator it = new StringCharacterIterator(text, 4, 27, 5);

        // In this loop we just iterator a subset of character defined in the
        // StringCharacterIterator above. It reads from the 4 index of the
        // string up to the 27 character. So it will just take the following
        // string "razorback-jumping frogs"
        for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
            System.out.print(ch);
        }
    }
}

The output of the code snippet above will be:

razorback-jumping frogs
← Jelajahi catatan lainnya