Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Parse String Posted by chandlerbing on 21 Mar 2005 at 2:57 PM
hello,

can someone help me with the following:

I am trying to create a simple method that takes in a string and a character.

the first thing i want to do is parse the string and then go in a compare each letter of the string to the character to see if it appeasr only once.

thanks!
Report
Re: Parse String Posted by ronenm on 21 Mar 2005 at 3:13 PM
: hello,
:
: can someone help me with the following:
:
: I am trying to create a simple method that takes in a string and a character.
:
: the first thing i want to do is parse the string and then go in a compare each letter of the string to the character to see if it appeasr only once.
:
: thanks!
:

there's a string command... you can do a simple for loop and go letter by letter. i think its like this:

String str = "im beautiful"
char c = 'i'

then do :
for i --> length
if str.charAt[place] == c .....blah
Report
Parse String - Need more!!! Posted by chandlerbing on 21 Mar 2005 at 3:24 PM
This message was edited by chandlerbing at 2005-3-21 15:46:24

: : hello,
: :
: : can someone help me with the following:
: :
: : I am trying to create a simple method that takes in a string and a character.
: :
: : the first thing i want to do is parse the string and then go in a compare each letter of the string to the character to see if it appeasr only once.
: :
: : thanks!
: :
:
: there's a string command... you can do a simple for loop and go letter by letter. i think its like this:
:
: String str = "im beautiful"
: char c = 'i'
:
: then do :
: for i --> length
: if str.charAt[place] == c .....blah
:

Sorry, this doesn't help much... I am bad with programming.. just beginning..

But, the what I am trying to do is this:

if someone gives me a string: ex. "Hello"

I want to put this string into an array: H-e-l-l-o so that I can compare each letter for each array aposition to see if it does appear and then to see if it appears once...




Report
Re: Parse String - Need more!!! Posted by Vilanye on 21 Mar 2005 at 7:12 PM
: This message was edited by chandlerbing at 2005-3-21 15:46:24

: : : hello,
: : :
: : : can someone help me with the following:
: : :
: : : I am trying to create a simple method that takes in a string and a character.
: : :
: : : the first thing i want to do is parse the string and then go in a compare each letter of the string to the character to see if it appeasr only once.
: : :
: : : thanks!
: : :
: :
: : there's a string command... you can do a simple for loop and go letter by letter. i think its like this:
: :
: : String str = "im beautiful"
: : char c = 'i'
: :
: : then do :
: : for i --> length
: : if str.charAt[place] == c .....blah
: :
:
: Sorry, this doesn't help much... I am bad with programming.. just beginning..
:
: But, the what I am trying to do is this:
:
: if someone gives me a string: ex. "Hello"
:
: I want to put this string into an array: H-e-l-l-o so that I can compare each letter for each array aposition to see if it does appear and then to see if it appears once...
:

Do you know the basics of loops? If so, use a for loop. Then look up the length(), charAt() and compareTo(), equals() or equalsIgnoreCase() methods in the String class.


Report
Re: Parse String - Need more!!! Okie Posted by benges on 21 Mar 2005 at 7:21 PM
This message was edited by benges at 2005-3-21 19:23:28

: : This message was edited by chandlerbing at 2005-3-21 15:46:24

: : : : hello,
: : : :
: : : : can someone help me with the following:
: : : :
: : : : I am trying to create a simple method that takes in a string and a character.
: : : :
: : : : the first thing i want to do is parse the string and then go in a compare each letter of the string to the character to see if it appeasr only once.
: : : :
: : : : thanks!
: : : :
: : :
: : : there's a string command... you can do a simple for loop and go letter by letter. i think its like this:
: : :
: : : String str = "im beautiful"
: : : char c = 'i'
: : :
: : : then do :
: : : for i --> length
: : : if str.charAt[place] == c .....blah
: : :
: :
: : Sorry, this doesn't help much... I am bad with programming.. just beginning..
: :
: : But, the what I am trying to do is this:
: :
: : if someone gives me a string: ex. "Hello"
: :
: : I want to put this string into an array: H-e-l-l-o so that I can compare each letter for each array aposition to see if it does appear and then to see if it appears once...
: :
:
: Do you know the basics of loops? If so, use a for loop. Then look up the length(), charAt() and compareTo(), equals() or equalsIgnoreCase() methods in the String class.
:
:
: okie let get it clear,

here how:
// an integer to hold length of your string
int tmpI = 0;
boolean found = false;
// loop through the string you have
for (tmpI = 0; tmpI <= yourStr.length() - 1; tmpI++){
// comparing the character and the 1 you wanna compare to, if that is CHARACTER!!! else use "yourStr.equalsIgnoreCase(<yourAnotherStr>)"
  if (yourStr.charAt(tmpI) == yourChar){
// get it!
    found = true;
    break;
  }
}

if (found == true)
  System.out.println("\tFound the character at: " + tmpI + ", Character: " + yourStr.charAt(tmpI));
else
  System.out.println("\tNot found!");






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.