Split Demo using RegularExpression

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


 
Ads

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

Ads
Share on Google+Share on Google+

Split Demo using RegularExpression

Posted on: August 26, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Split Demo using RegularExpression   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads