Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Parsing Character-Separated Data with a Regular Expression

This section illustrates you how to split String data (separated by "," or "and/or").

Parsing Character-Separated Data with a Regular Expression

                         

This section illustrates you how to split String data (separated by "," or "and/or"). These words are shown in a new line without the word or characters which is used for separation the word of the sentences through the given regular expression of the following program.

Program Result:

This program takes a complete string or text with the many separation of words and detects every comma, and|or separation from the given sentences. It besides all word or the collection of words from where the comma or and|or separation is used. The complete separate word is shown in a new line.

Code Description:

String[] str = string.split("[, ]+(and|or)*[ ]"):
Above code splits the value of String type variable string with the ","(comma), " ", "and" or "or" separators and store it into a String array str which value is shown by the following program one-by-one.

Here is the code of the program:

import java.util.regex.*;
import java.io.*;

public class ParseSeparatedData{
  public static void main(String[] argsthrows IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter string for finding separated data: ");
    String string = in.readLine();
    String[] str = string.split("[, ]+(and|or)*[ ]");
    for (int i = 0; i < str.length; i++){
      System.out.println(str[i]);
    }
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c reference methods references method user system using id package node create check if preferences for call exists to automatic

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.