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 4 of 4

Thread: complete noob, direction needed pls.

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

    Default complete noob, direction needed pls.

    good day.

    i'm busy downloading the java sdk to start my journey down the path of becoming a java bean.

    i've got an simple app thati want to try building (i know i havea large learning curve to get over)...

    i want to create an app that would take an input string and convert each character to a different character, eg. abcd would become bcde. But i know that using a search and replace function as:
    replace a with b, b with c, d with e means that my program will give me a string if i where to build the step line by line
    1: bbcd
    2: cccd
    3: dddd
    4: eeee

    how would you do a selective search and replace or translating or encoding (i dont know what to lable it)... without encountering the above

    thank you in advanced ( and for not critizing my lack of knowledge yet)


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

    Default Re: complete noob, direction needed pls.

    Use different methods and/or classes that allow you to work on the characters one at a time from left to right instead of working on all of the characters each time.
    Look at the String class's methods
    or the StringBuffer or StringBuilder classes that have methods to access and change individual characters.
    Last edited by Norm; October 1st, 2012 at 11:17 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: complete noob, direction needed pls.

    A simple solution is to make all the changes at the same time.

    Create a remap method which takes in the input character and what the appropriate output character should be.

    Then create a StringBuilder object. This is essentially a mutable String. Then for every character in the old String set the result in the new StringBuilder to the remapped character.

    Finally, to convert the StringBuilder object to a String, call the toString method.

  4. #4
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: complete noob, direction needed pls.

    Who said you had to make the changes to the original string? Copy it, then reference back to the original as you make the changes, finally return the copy when it's all done

Similar Threads

  1. Direction Needed for Newbie
    By SWWeatherGuy in forum Java Theory & Questions
    Replies: 0
    Last Post: September 30th, 2012, 04:08 PM
  2. HI WORLD! Can anyone point a complete novice in the right direction??
    By Irish-novice in forum Member Introductions
    Replies: 4
    Last Post: June 26th, 2012, 05:16 PM
  3. Complete Noob -- A little help would be appreciated...
    By echmiel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 5th, 2012, 05:31 PM
  4. need a bump in the right direction
    By mszyndlar in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 15th, 2011, 01:38 AM
  5. Direction,
    By Time in forum Algorithms & Recursion
    Replies: 2
    Last Post: May 21st, 2010, 05:21 PM