Mustafa Ozan Vural Mobil teknoloji notlari

14Jan/110

Java ME String Split

Kullanım :

String text = "1,2,3,4,5,6";
String[] splitedText = split(text, ",");

for (int i = 0; i < splitedText.length; i++) {
    System.out.println(splitedText[i]);
}

Çıktı :

1
2
3
4
5
6

Fonksiyon :

 public static String[] split(String original, String separator) {
        Vector nodes = new Vector();
        int index = original.indexOf(separator);
        while(index>=0) {
            nodes.addElement( original.substring(0, index) );
            original = original.substring(index+separator.length());
            index = original.indexOf(separator);
        }
        nodes.addElement( original );
        String[] result = new String[ nodes.size() ];
        if( nodes.size()>0 ) {
            for(int loop=0; loop<nodes.size(); loop++)
                result[loop] = (String)nodes.elementAt(loop);
        }
        return result;
 }
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.