Solved: no suitable method found for replace(char,String)

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ElementOfMagic

Thread Starter
Joined
Dec 30, 2012
Messages
52
Hello. :)


I am attempting to write a simple program, that determines whether the char variable 'sl1' (currently set to 'H' in my program) is in the string variable 'pr_word' (input by the user via a textfield) and, if so, removes that character from the string when the string is output. It also replaces that character with a polygon.

However, at the moment I'm getting the error "no suitable method found for replace(char,String)" and I'm not sure why. :confused: :(


This is the fragment of code that does what I mentioned above: ^

Code:
if(pr_word.indexOf(sl1)!=-1)
		{
		   pr_word = pr_word.replace(sl1, "");
		   g.setColor(Color.red);
		   g.drawPolygon(x,y,5);
		}
Any help/guidance will be greatly appreciated. :) (y)
 
Joined
Jul 2, 2006
Messages
379
In Java i believe you can only replace a character with another character. Sl1 is a character but "" is a string. You need to use '' (two single quotes) to represent nothing.
 

ElementOfMagic

Thread Starter
Joined
Dec 30, 2012
Messages
52
In Java i believe you can only replace a character with another character. Sl1 is a character but "" is a string. You need to use '' (two single quotes) to represent nothing.
By the way, do you know if it's possible to replace a character with a polygon, in any instance of that character's occurrence in a string?
For example, if I typed-in the word 'Holly' and hit 'enter', the first letter would be replaced by the polygon.
If I then went to type the word 'thistle', the polygon's new position would be in place of the second letter?
 
Joined
Jun 19, 2004
Messages
7,800
You want to put polygons in strings? Or just appear to be?

Really, what you would probably have to do is get the x,y of the text box, replace the char with a space (or two) and then paint the polygon over the form and label.
 

ElementOfMagic

Thread Starter
Joined
Dec 30, 2012
Messages
52
You want to put polygons in strings? Or just appear to be?
I want it to appear as if a specific character in a string is being replaced by a drawn/filled polygon.

Really, what you would probably have to do is get the x,y of the text box, replace the char with a space (or two) and then paint the polygon over the form and label.
I see. How would I go about doing that?
 
Joined
Jun 19, 2004
Messages
7,800
What are you using? Swing? What about for the polygons? Lines from Swing, or JavaFX?
 
Joined
Jun 19, 2004
Messages
7,800
Either way, gather your requirements, mark this thread as solved and please start a new one. We don't want to dilute the solution to this thread with another question and answer.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top