Home Regularexpressions Split Demo using RegularExpression



Split Demo using RegularExpression
Posted on: August 26, 2008 at 12:00 AM
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(< font color="#000000">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

Related Tags for Split Demo using RegularExpression:
cstringiosplitexpressionusingthisexampletoexpressexamssieitdeslisplulinmtresdescribexaxampsspessismplpressprearstrxpscrssriringthstpleplprono


More Tutorials from this section

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

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.