CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: drawString

  1. #1
    Join Date
    Jan 2000
    Location
    CA, USA
    Posts
    305

    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



  2. #2
    Join Date
    Dec 1999
    Location
    Chonghe, Taipei County, Taiwan, R.O.C.
    Posts
    231

    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



  3. #3
    Join Date
    Jan 2000
    Location
    CA, USA
    Posts
    305

    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



  4. #4
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    124

    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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured