Solved: Is it possible to replace a character in a string with a polygon?

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 was wondering if it was 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?

This is my code fragment, the character I want to replace is called sl1.

Code:
if(pr_word.indexOf(sl1)!=-1)
		{
		   pr_word = pr_word.replace(sl1, ' ');
		   g.setColor(Color.red);
		   g.fillPolygon(xh,yh,5);
		   
		   g.setColor(Color.white);
		   g.fillRect(352,40,18,20);
		}
Any help/guidance will be greatly appreciated. :) (y)
 
Joined
Jan 20, 2002
Messages
433
If your string is stored in Unicode, you can replace a character with a Unicode character. There are many Unicode characters, including some that are geometric shapes, check out this reference for starters: http://en.wikipedia.org/wiki/Geometric_Shapes

However this won't give you the ability to change the color. Without going into too much detail, your question is mixing two different concepts. One concept is a string, which is a series of characters. The other concept is the display of characters on a display device, which is a more complex subject and depends on the windowing system.

While a string can be rendered onto a display device, the string itself has no information or knowledge of where the characters are displayed, what font is used, what color is used, etc. So in your code fragment, there is no way to determine the coordinates. Also, you code can't know the size of the font, so you won't be able to determine the size of the polygon.
 

ElementOfMagic

Thread Starter
Joined
Dec 30, 2012
Messages
52
If your string is stored in Unicode, you can replace a character with a Unicode character. There are many Unicode characters, including some that are geometric shapes, check out this reference for starters: http://en.wikipedia.org/wiki/Geometric_Shapes

However this won't give you the ability to change the color. Without going into too much detail, your question is mixing two different concepts. One concept is a string, which is a series of characters. The other concept is the display of characters on a display device, which is a more complex subject and depends on the windowing system.

While a string can be rendered onto a display device, the string itself has no information or knowledge of where the characters are displayed, what font is used, what color is used, etc. So in your code fragment, there is no way to determine the coordinates. Also, you code can't know the size of the font, so you won't be able to determine the size of the polygon.
Thanks, but it's not a Unicode character I want to replace the character in the string with - it's the polygon I 'drew' using the fillPolygon() method (it is mentioned in my code ^^).
 
Joined
Jan 20, 2002
Messages
433
When I answer a question, I try to understand the writer's intent, so that I can try to be helpful even if the question is worded in a way that makes it difficult to provide a good answer. That's the reason I mentioned the Unicode approach, even though I knew it was a long shot. The other two paragraphs that I wrote attempted to provide a bit more explanation.

The simple and precise answer to your question is "No, It is not possible to replace a character in a string with a polygon". The reason is that a string can only contain characters. A polygon is not a character.
 
Joined
Jun 19, 2004
Messages
7,800
The simple and precise answer to your question is "No, It is not possible to replace a character in a string with a polygon". The reason is that a string can only contain characters. A polygon is not a character.
Though you could probably approximate it as far as the way the end result goes. I can't see it being practical... but the logic would probably be something like:

Code:
varXY = label.XY
char[] FindChar = stringToPlayWith

indexOfChar toReplace = replace(' ")

callMethodForPoly(varXY, IndexOfChar)

callMethodForPoly{
x = varX.X + (width of chars * indexOfChar)
y = varXY.Y

PolyPaintMethod(left = X, top = Y, height = Char.Height, width = Char.width)
}
That is in no way Java, btw. I just wanted to give you something to think about for a way to do it. Honestly though, I can't see that this would ever be practical in a desktop app.
 
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

Staff online

Top