Total members 11890 |It is currently Thu Apr 25, 2024 5:01 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Breaking the String into Words
Code:
import java.io.*;
import java.util.*;

public class BreakStringToWord{
  String str;
  int count = 0;
  public static void main(String[] args) {
    BreakStringToWord c = new BreakStringToWord();
  }
  public BreakStringToWord(){
    try{
      InputStreamReader ir = new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(ir);
      System.out.print("Enter String: ");
      str = br.readLine();
      System.out.println("Enter String is : "+ str);
      System.out.println("Breaking this string is : ");
      StringTokenizer token = new StringTokenizer(str);
      while (token.hasMoreTokens()){
        count++;
        str = token.nextToken();
        System.out.println(str);
      }
      System.out.println("Number of Words : "+ count);
    }
    catch(IOException e){}
  }
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

What a joy to find such clear tihinnkg. Thanks for posting!



Author:
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Breaking the String into Words
 get number of words in a string     -  
 Return words count in a string     -  
 Breaking a Loop     -  
 sort words in c++     -  
 probability of repeated words     -  
 Change the letter spacing of the words     -  
 check if string ends with specific sub-string in php     -  
 check if string start with a specific sub-string in PHP     -  
 Splitting a String Based on a Found String     -  
 recursive string reversal- reverse string     -  



Topic Tags

Java Strings
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com