1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by ElementOfMagic, Feb 1, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. ElementOfMagic

    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)
     
  2. andythepandy

    andythepandy

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

    ElementOfMagic Thread Starter

    Joined:
    Dec 30, 2012
    Messages:
    52
    Thank-You, awesome person, I've got it working now. :) :D
     
  4. ElementOfMagic

    ElementOfMagic Thread Starter

    Joined:
    Dec 30, 2012
    Messages:
    52
    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?
     
  5. loserOlimbs

    loserOlimbs

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

    ElementOfMagic Thread Starter

    Joined:
    Dec 30, 2012
    Messages:
    52
    I want it to appear as if a specific character in a string is being replaced by a drawn/filled polygon.

    I see. How would I go about doing that?
     
  7. loserOlimbs

    loserOlimbs

    Joined:
    Jun 19, 2004
    Messages:
    7,800
    What are you using? Swing? What about for the polygons? Lines from Swing, or JavaFX?
     
  8. loserOlimbs

    loserOlimbs

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

    ElementOfMagic Thread Starter

    Joined:
    Dec 30, 2012
    Messages:
    52
  10. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1087855

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice