Home Regularexpressions Split Demo using RegularExpression
Questions:Ask|Latest

Related Tutorials


 
 

Share on Google+Share on Google+

Split Demo using RegularExpression

Advertisement
This Example describe the way to Split a String using Regularexpression.

Split Demo using RegularExpression

     

This Example describe the way to Split a String using Regularexpression. The steps involved in splitting a String are described below:-

 String text = "For some college -Presidents want law-revisited saying age limit-has not curbed-that problems on campuses":-This is the String to which we are splitting.

String Splitpoint = "-":-Point where the string is to be splitted.

 
 

SplitString.java

import java.util.*;
public class SplitString {
  public static void main(String[] args) {

String text = 
"For some college -Presidents want law-revisited" +
 
" saying age limit-has not curbed-that problems on campuses";
System.out.println("==========STRING BEFORE SPLITTING IS:=");

 System.out.println(text);
  new SplitString().split(text);
  }
  public void split(String Text) {
  String token[] null;
  String Splitpoint = "-";
  token = Text.split(Splitpoint);
 System.out.println("==========SPLITTED STRING IS:=======");

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

  }
}

Output of the program:-
==========STRING BEFORE SPLITTING IS:==========
For some college -Presidents want law-revisited saying
age limit-has not curbed-that problems on campuses
==========SPLITTED STRING IS:==========
For some college
Presidents want law
revisited saying age limit
has not curbed
that problems on campuses
========================================
Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 26, 2008

Related Tutorials

Ask Questions?    Discuss: Split Demo using RegularExpression   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com