Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Parse String

chandlerbingchandlerbing Posts: 2Member
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!

Comments

  • ronenmronenm Posts: 41Member
    : 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
  • chandlerbingchandlerbing Posts: 2Member
    [b][red]This message was edited by chandlerbing at 2005-3-21 15:46:24[/red][/b][hr]
    : : 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...




  • VilanyeVilanye Posts: 684Member
    : [b][red]This message was edited by chandlerbing at 2005-3-21 15:46:24[/red][/b][hr]
    : : : 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.


  • bengesbenges Posts: 331Member
    [b][red]This message was edited by benges at 2005-3-21 19:23:28[/red][/b][hr]
    : : [b][red]This message was edited by chandlerbing at 2005-3-21 15:46:24[/red][/b][hr]
    : : : : 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:
    [code]
    // 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(" Found the character at: " + tmpI + ", Character: " + yourStr.charAt(tmpI));
    else
    System.out.println(" Not found!");
    [/code]


Sign In or Register to comment.