Posted by: iBNuX | June 2, 2010

Fungsi Split untuk Java

fungsi ini akan bantu anda untuk split String.

kode fungsinya

            public synchronized String[] split(String original, String separator) {
                Vector nodes = new Vector();

                // Parse nodes into 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);
                }
                // Get the last node
                nodes.addElement( original );

                // Create splitted string array
                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;
            } 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: