-
drawString
Hi,
I need to paint a text string consisting of
'\n' char in between. I tried using drawString
method but gets me a junk whereever '\n' occurs.
Is there a simple way of solving this problem
without parsing the text?
e.g.
g.drawString("This is \n a test");
gets me the output like this:
This is 'junk' a test
Thanks.
Kannan
-
Re: drawString
I guess that you might need to parse that string and unpack it to several substring for display.
Say , a string, I have a friend \n living in Taiwan.\n Because I also live in \n Taiwan.\n. You
might parse this string and get the following substring for ready to dispay.
I have a friend
living in Taiwan.
Because I also live in
Taiwan.
I think that this might be the case that you do not want to meet. But unfortunately, My
past experience told me that there is no way to get rid of the new line character when
show the string when using drawString(). Perhaps others have the alternative answer to
help you out this question.
good luck,
Alfred Wu
-
Re: drawString
Hi Alfred,
Thanks for your reply. But as I said,
I was just wondering if there was a simpler way
of solving the problem without parsing the
text for '\n' char.
Kannan
-
Re: drawString
Kannan,
The simplest way to deal with a '\n' character is to ignore it.
Alfred is right. It's up to You to do carriage returns when using the drawString() method.
So if you don't want to mess around with new lines and whatnot, do something like change all instances of the '\n' character to a space or something, otherwise you will always get garbage.
Here's a code snippet that will do this for you:
// let's say String theText is where the string is stored
// just do this...
theText.replace('/n',' ');
// the above line replaces all instances of '/n' to a space ' '.
Good luck.
Regards,
dogBear