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

Thread: replacing elements in a string

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default replacing elements in a string

    I changed the post in the wrong section and posted it here.

    I'm trying to encrypt a string when you enter a phrase into the program. The following code compiles with no errors but it doesn't change the a when its there to "00". The phrase is printed out again telling me that the if statement is working but its not replacing it and I have no idea how to fix this. This is just a fun project for me but this is really frustrating me...

    		input.getUserInput(choice);
     
    		if (input.input.equals("1")) {
     
    			pdphrase = input.getUserInput(dphrase);
     
    			if (pdphrase.contains("a")) {
     
    				pdphrase.replaceAll("a", "00");
     
    			        System.out.println(pdphrase);
     
     
    			}		
     
    		}

    P.S. dphrase means decrypted phrase and pdphrase means post decryption phrase.


  2. #2
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: replacing elements in a string

    try
    pdphrase = pdphrase.replaceAll("a", "00");

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

    sp11k3t3ht3rd (January 10th, 2011)

  4. #3
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: replacing elements in a string

    Wow... ...Thanks!

Similar Threads

  1. Help with Arrays - Counting elements
    By ShakeyJakey in forum Collections and Generics
    Replies: 7
    Last Post: August 8th, 2010, 04:09 PM
  2. [SOLVED] replacing subString
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 21st, 2010, 09:47 PM
  3. dispose()'ing a JFrame and replacing it
    By musasabi in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 14th, 2010, 02:31 PM
  4. accessing elements in a 2d ArrayList
    By Flamespewer in forum Collections and Generics
    Replies: 2
    Last Post: March 8th, 2010, 05:11 PM