Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Basic string question

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Basic string question

    Hi everyone,

    I am fairly new at programming and I was wondering how I could identify acronyms(combinations of characters with all capital letters such as OMG or WTF) in a text file. For example if the whole text was, "OMG I have no idea what I am doing right now, WTF!" The acronyms would be OMG and WTF, and the count would be 2. All other capitalized letters do not count since they do not have more than 1 consecutive capital letter. So basically if anyone could help me with identifying such acronyms and adding them to a count I would be very grateful!

    P.S. Please show me the most basic way of doing this, such as using a for loop/other loops; since I do not have access to things such as arrays in the question!

    Thanks!
    ADHDG


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Basic string question

    Look at the String class for useful methods.

    How are you going to store the list of acronyms and their usage counts if you can't use arrays?
    Using a bunch of variable names like: cnt1, cnt2, cnt3 is NOT the way to do it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    adhdG (November 11th, 2013)

  4. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Basic string question

    Couldnt I use a for loop and check every letter for a capital, then create an if statement with the condition to count an acronym only if there are two capital letters following each other?

    --- Update ---

    The problem is that I cant seem to find a proper way to identify a character as an upper case letter!

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Basic string question

    I cant seem to find a proper way to identify a character as an upper case letter
    Look at the Character class.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Basic string question

    One option would be to split the text into words, for each word that has a length of 2 or greater convert to uppercase, compare to original if they are the same then it was already all uppercase and therefore an acronym.
    Improving the world one idiot at a time!

  7. The Following User Says Thank You to Junky For This Useful Post:

    adhdG (November 12th, 2013)

Similar Threads

  1. Rather Basic Question
    By ashl7 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: March 6th, 2013, 03:20 AM
  2. Basic Question Need Help
    By Graser in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 21st, 2012, 10:27 AM
  3. Need basic String help
    By Sadalmelik in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2011, 06:05 AM
  4. Basic java question
    By erosgol in forum Java Theory & Questions
    Replies: 5
    Last Post: September 2nd, 2011, 05:24 PM
  5. please answer some basic question
    By togaurav in forum Java Theory & Questions
    Replies: 5
    Last Post: April 16th, 2011, 07:58 AM