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!");