• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A program to count no of characters in String

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends, Can anybody tell me the program that counts the no of characters in the string which is entered as command line argument. It is assumed that only one command line argument is entered. for example if user enters "press" as a command line argument then the output should be like : p1r1e1s2

Also (I know this is a java forum but) can anyone tell me the javascript function for validating an email-id.

Thanks,
Pankaj
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like homework, and there are a number of ways to proceed. Did you want to show us what you have, or explain your approach?
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well!!
you have said that you want to count the number of characters in a string but the string will be entered as command line argument try the below shown code.

First you take a buffered reader class(for this class import java.io.BufferedReader; as well as InputStreamReader) create its object ,use readline method to get input from command line.

BufferedReader buff;
buff=new BufferedReader(new InputStreamReader(System.in));

int i=0;
i=Integer.parseInt(buff.readline());
I am not that sure about its working because i have not tried it.....
i hope it helps you to atleast some extent.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It could be more simple.

Just use the method toCharArray() of the String which will return an Array of Chars. You can now use the length property of the Array for determining the number of characters.

See the following link for code.

String functions
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Remko Strating:
It could be more simple.

Just use the method toCharArray() of the String which will return an Array of Chars. You can now use the length property of the Array for determining the number of characters.

See the following link for code.

String functions



In fact if you take a close look at the String API, you will find a method that directly returns the number of characters, without having to create a character array.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic