Results 1 to 8 of 8
Thread: String Replacement
- 12-16-2010, 11:27 AM #1
Member
- Join Date
- Dec 2010
- Location
- Netherlands
- Posts
- 6
- Rep Power
- 0
String Replacement
Hi, I'm going to start to learn Java outside of college. Learning Java in making own programs etc. Not scholar programs.
But I have a problem in getting text back. What do I need to add to this text?
package ontsleuteling1;
public class Replace
{
public static String replacement(String args[])
{
String str="ryhhf,MleiDffkwstkGyyoFfwTloIyykFbols2.Pyykfm RsuLwGlzosksiFihlisdlyOfkSsiKswsiligGsfbsip.RsoItm mskLz978.245.823.456Gkfso,Gfivf";
str.replaceAll( "F","O" );
str.replaceAll( "f","o" );
str.replaceAll( "G","G" );
str.replaceAll( "g","g" );
str.replaceAll( "H","L" );
str.replaceAll( "h","l" );
str.replaceAll( "I","N" );
str.replaceAll( "i","n" );
str.replaceAll( "R","H" );
str.replaceAll( "r","h" );
str.replaceAll( "V","Z" );
str.replaceAll( "v","z" );
str.replaceAll( "Y","A" );
str.replaceAll( "y","a" );
return str;
// System.out.print(str); --> doesn't work, why not?
}
}
- 12-16-2010, 11:42 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
replaceAll method returns another string. So your code should look like
str=str.replaceAll( "F","O" );Swastik
- 12-16-2010, 11:51 AM #3
Member
- Join Date
- Dec 2010
- Location
- Netherlands
- Posts
- 6
- Rep Power
- 0
okay, thanks. I replaced. Could you tell me why I can't put the System.out.println("str"); there?
Last edited by pr3diker; 12-16-2010 at 11:53 AM. Reason: incorrect english
- 12-16-2010, 11:54 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
You have a return statement before that, so the flow control will never reach to that line. You may put that print statement before return.
Swastik
- 12-16-2010, 11:56 AM #5
Member
- Join Date
- Dec 2010
- Location
- Netherlands
- Posts
- 6
- Rep Power
- 0
Console : Exception in thread "main" java.lang.NoSuchMethodError: main
- 12-16-2010, 11:57 AM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Have you coded the main function in your class?
Swastik
- 12-16-2010, 12:01 PM #7
Member
- Join Date
- Dec 2010
- Location
- Netherlands
- Posts
- 6
- Rep Power
- 0
it works now :)
package ontsleuteling1;
public class Replace
{
public static void main(String args[])
{
String str="ryhhf,MleiDffkwstkGyyoFfwTloIyykFbols2.Pyykfm RsuLwGlzosksiFihlisdlyOfkSsiKswsiligGsfbsip.RsoItm mskLz978.245.823.456Gkfso,Gfivf";
str = str.replaceAll( "F","O" );
str = str.replaceAll( "f","o" );
str = str.replaceAll( "G","G" );
str = str.replaceAll( "g","g" );
str = str.replaceAll( "H","L" );
str = str.replaceAll( "h","l" );
str = str.replaceAll( "I","N" );
str = str.replaceAll( "i","n" );
str = str.replaceAll( "R","H" );
str = str.replaceAll( "r","h" );
str = str.replaceAll( "V","Z" );
str = str.replaceAll( "v","z" );
str = str.replaceAll( "Y","A" );
str = str.replaceAll( "y","a" );
System.out.println( str + "");
}
}
- 12-16-2010, 12:04 PM #8
Member
- Join Date
- Dec 2010
- Location
- Netherlands
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Binary-algorithm -> Insert String to sorted String-ArrayList
By Muskar in forum Advanced JavaReplies: 12Last Post: 11-26-2010, 08:33 AM -
Test for all empty Strings in LinkedHashMap<String,ArrayList<String>
By albertkao in forum New To JavaReplies: 1Last Post: 11-04-2010, 06:53 PM -
shared sub visual basic/ java replacement?
By dinosoep in forum New To JavaReplies: 3Last Post: 08-11-2010, 02:44 PM -
String replacement...
By diskhub in forum New To JavaReplies: 6Last Post: 05-19-2010, 04:20 AM -
Looking for JGroups replacement
By asynchrony in forum NetworkingReplies: 4Last Post: 10-17-2008, 10:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks