Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-04-2008, 03:39 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default How to split a String using split function
This tip will show the use of split function to split a String according to particular separator character.

In this program Split() function is splitting the String according to ‘:’.

Code:
public class StringSplit {
 
public void doit() {
 	String str = "CompChamps:Guys:are:There";
 	String [] temp = null;
 	temp = str.split(":");
 	dump(temp);
}

public void dump(String []s) {
 	for (int i = 0 ; i < s.length ; i++) {
 		System.out.println(s[i]);
 	}
}
}
public static void main(String args[]) throws Exception{
  	StringSplit ss = new StringSplit();
             ss.doit();
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-26-2008, 08:51 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 144
Rep Power: 0
jazz2k8 is on a distinguished road
Thumbs up
Try this code :
Quote:
public class splitdemo {

private static String REGEX = ":";
private static String INPUT = "CompChamps:Guys:are:There";
public static void main(String[] argv) {
/*A compiled representation of a regular expression.
regular expression, specified as a string, must first be compiled into an instance of this class.*/
Pattern p = Pattern.compile(REGEX);
// editing your input file, regex.txt
String[] items = p.split(INPUT);
for (int i = 0; i < items.length; i++) {
System.out.println(items[i]);
}
}
}
__________________
visit : www.yoteam.co.cc
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with split method abhiN New To Java 7 02-10-2009 02:54 PM
how to split a file nagaraaju New To Java 0 03-14-2008 09:45 AM
How to split a string into multiple lines of x characters each JackJ New To Java 3 12-17-2007 03:35 AM
How to split a String using split function JavaBean Java Tips 0 10-04-2007 10:32 PM
PDF Split and Merge 0.7 beta 1 JavaBean Java Announcements 0 06-24-2007 09:46 AM


All times are GMT +2. The time now is 01:01 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org