Results 1 to 16 of 16

Thread: CString and Escape Sequence Inconsistency ...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Angry CString and Escape Sequence Inconsistency ...

    Hi Everyone,

    I've encountered a problem that I can't solve .... and it seems that it shouldn't be a problem at all! I'm trying to populate a (CString) multiline edit box with a CString value that contains "\r\n". If I populate the edit box as follows, everything works fine with the Lines being on different rows:
    VB Code:
    1. m_edtMessage = "Line1\r\nLine2\r\nLine3\r\nLine4";
    2. UpdateData(FALSE);
    But if I use a variable instead, such as:
    VB Code:
    1. m_edtMessage = g_miParameterInfo[sArrayCtr].sz_Parameter;
    2. UpdateData(FALSE);
    , everything just appears on the first line, including "\r\n".
    Can anyone help me out? This seems straightforward but I don't see why the variable method is not working.

    Thanks in advance.

    OneSource

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What is the content of the variable? A command line parameter?

    Escape sequences have their name for a reason.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question Corned Bee ...

    Thanks for your reply. I apologize for the confusion.

    I'm relatively new to Visual C++, so I'm not sure what a "command line paramenter" is. But the content of the variable is exactly the same as the string in my first post, namely "Line1\r\nLine2\r\nLine3\r\nLine4". I tried populating the edit box with the string and it worked just fine (the edit box contained 4 lines of text). But if I assign the string to the variable and use the variable to populate the edit box, there are no hard returns ... everything appears on the first line. Corned Bee, any help you or anyone else could provide would be greatly appreciated.

    Thanks,

    One Source

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    How do you assign the string to the variable?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question Corned Bee ...

    like this:
    VB Code:
    1. g_miParameterInfo[sArrayCtr].sz_Parameter = "Line1\r\nLine2\r\nLine3\r\nLine4";

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is indeed strange...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Could you upload your entire code or is it copyrighted or closed?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Unhappy Corned Bee ...

    My project is rather big and also has a database component; therefore, it wouldn't be a good idea to upload it.

    I created a little test app and the multiline edit box did display correctly even when I used a variable to populate it. So, I guess the problem is that the CString variable in my problem app is being populated with info. from an Access database. After that, I am putting the variable info. into the edit box. I don't know why this would be a problem because I'm using CStrings for all of the data transfers. The string in the database is, for example, "Line1\r\nLine2\r\nLine3\r\nLine4", but the "\r\n" 's are not being interpreted as such by VC++. Any ideas?

    Thanks ...

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Ahhhh. The \r and \n are interpreted by the *compiler*, not the runtime. You'd need to actually have the characters 10 and 13 in there for it to notice.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question Parksie ...

    It definitely sounds like the solution is near!
    You'd need to actually have the characters 10 and 13 in there for it to notice.
    Will you please show me how these characters should be stored in the database in order for the runtime to notice them?

    Thanks.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Um. You just need to somehow force it in there. How are you storing the data? In your interface, if you're entering the values, have that check for \n or \r and automatically replace it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Lightbulb Parksie ...

    Automatically replacing the data isn't a problem. But I was asking what format the "10 and 13" needed to be in in order for the VC++ runtime to recognize them. For example, would this register as a hard return: "\10\13"?

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No, look up how to embed octal escape codes. But that will still only be at the *compiler*. You need to tell it to put characters '\n' and '\r' in, to replace the strings "\n" and "\r".
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question As good as it gets?

    Parksie,

    With a little work, I was able to populate the multiline edit box using the information from your post. I couldn't simply store '\r' and '\n' in the database field because it would just be viewed as part of the field itself just like "\r\n" is. I guess that this is "as good as it gets" as far as trying to achieve my desired end result. But things would be much simpler if the VC++ runtime interpreted "\r\n" like the compiler does. There's no way to make it do this?

    By the way, thanks for your help Parksie. You too, Corned Bee. You probably would have been able to figure out the problem if I had mentioned in the beginning that the info. populating the string variable was coming from a database field.

    Thanks again,

    OneSource

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No, you need to convert the \r and \n to their respective numbers *yourself*. The escape codes are a feature of the compiler. It's simple enough to do.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's what I was thinking.

    Anyway, it wouldn't be good if the runtime interpreted escape sequences. You might overlook a single place where it happens and you already had a bug.

    It's easy enough to write such a function yourself.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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