Activity Stream
227,828 MEMBERS
11017 ONLINE
greengrassforums On YouTube Subscribe to our Newsletter greengrassforums On Twitter greengrassforums On Facebook greengrassforums On Google+
banner1

Results 1 to 2 of 2

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1.     
    #1
    Senior Member

    Iterating through the characters in a string (java)

    If anyone can offer help, I'd be very happy!

    I have to write a program in java for my coursework, and part of it involves reading in strings from a file. That's all fine and dandy.

    Once I have the string, I need to get the separate characters. For example, if my string is "otcl" I need to have "o", "t", "c" and "l".

    I know how to iterate through the string to get separate characters, but the length of the strings vary - from 1 to 6 characters. I need to get the separate characters, and compare them to the characters from subsequent strings.

    It's possible I'm being incredibly stupid about this, seeing as I've been working on it for ages, and my brain's beginning to shut down... but...

    If I'm iterating through the string, and I don't know how long it will be, how do I keep track of the characters?

    This is my code so far:

    CharacterIterator charIt = new StringCharacterIterator(cLikes);

    // Iterate over the characters in the forward direction
    for (char c = charIt.first(); c != CharacterIterator.DONE ; c = charIt.next() )
    {
    //get the separate characters
    }

    Am I being really stupid? I had the idea of creating an array list, and adding c in on each iteration. Is that a bad idea?

    Gah, I hate coursework.
    psychopixi Reviewed by psychopixi on . Iterating through the characters in a string (java) If anyone can offer help, I'd be very happy! :D I have to write a program in java for my coursework, and part of it involves reading in strings from a file. That's all fine and dandy. Once I have the string, I need to get the separate characters. For example, if my string is "otcl" I need to have "o", "t", "c" and "l". I know how to iterate through the string to get separate characters, but the length of the strings vary - from 1 to 6 characters. I need to get the separate characters, Rating: 5

  2.   Advertisements

  3.     
    #2
    Senior Member

    Iterating through the characters in a string (java)

    Anyone help?

Similar Threads

  1. Invalid Characters in User Name
    By Dro_Princess in forum Feedback and Suggestions
    Replies: 20
    Last Post: 10-14-2006, 03:05 AM
  2. More television characters are going to pot
    By Psycho4Bud in forum Activism
    Replies: 2
    Last Post: 08-03-2005, 04:15 PM
  3. Characters?????
    By LOVElife in forum Marijuana Methods
    Replies: 14
    Last Post: 04-19-2005, 05:43 PM
  4. Cereal Characters
    By Omun in forum GreenGrassForums Lounge
    Replies: 17
    Last Post: 02-27-2005, 01:21 AM
Amount:

Enter a message for the receiver:
BE SOCIAL
GreenGrassForums On Facebook