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



## ElementOfMagic (Dec 30, 2012)

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.  

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


```
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.  :up:


----------



## andythepandy (Jul 2, 2006)

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 (Dec 30, 2012)

andythepandy said:


> 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.


Thank-You, awesome person, I've got it working now.


----------



## ElementOfMagic (Dec 30, 2012)

andythepandy said:


> 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?


----------



## loserOlimbs (Jun 19, 2004)

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 (Dec 30, 2012)

loserOlimbs said:


> 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?


----------



## loserOlimbs (Jun 19, 2004)

What are you using? Swing? What about for the polygons? Lines from Swing, or JavaFX?


----------



## loserOlimbs (Jun 19, 2004)

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.


----------



## ElementOfMagic (Dec 30, 2012)

loserOlimbs said:


> 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.


Done, the new thread can be found here: http://forums.techguy.org/software-...-display-certain-char-string.html#post8604297


----------

