Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split function 1

Status
Not open for further replies.

jby1

Programmer
Apr 29, 2003
403
GB
Hi

Is there a Split function in Java? ie a function that will take a string and delimiter, and return an array?

Cheers
 
Used a java.util.StringTokenizer object to solve this.
 
Here is another way:

Code:
//Done to save space
import java.util.regex.*;

public class ParseFile
{
	public static void main(String[] args) throws Exception
	{
		Pattern pattern = Pattern.compile("::");
		// Creates a pattern to match breaks
		String[] result = patpattern.split("One::Two::Three::::four::Five");
		// Splits input with the pattern
		for (int i=0; i<result.length; i++)
		{
			System.out.println(result[i]);
		}
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top