NO

Author Topic: Replace \\r with \r (unescaping strings)  (Read 2990 times)

zeno

  • Guest
Replace \\r with \r (unescaping strings)
« on: April 24, 2008, 01:46:19 PM »
Hi There,

I have the following problem, I am creating a simple pocket pc forms application in pelles c.

My main looks like this:
Code: [Select]
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{

When I start the program with these args:   
Code: [Select]
app.exe some\r\ntext
And then use my lpszCmdLine in a DrawText method I literally see the \r\n instead of line breaks. (if I put a L"some\r'ntext" in code it works).

My guess is the \r\n get escaped to \\r\\n so have to undo this. I tried it with the following code:

Code: [Select]
// lpszCmdLine is my command line string, it's value is : Some\\r\\nText

    LPWSTR target = lpszCmdLine; // fill the target with the cmld so we have the minimum length.

    int targetCounter = 0;
    for( int i = 0; i < sizeof(lpszCmdLine); i++) {
    if( lpszCmdLine[i] == '\\' && i+1 < sizeof(lpszCmdLine) && lpszCmdLine[i+1] == '\\' ) {
            //skip
        }
        else {
            // copy the char
            target[targetCounter] = lpszCmdLine[i];
            targetCounter++;
        }
    }
    target[targetCounter] = "\0"; // add the \0 to terminate the string.


   
lpszCmdLineX = target; // lpszCmdLine;

But, as you probably guessed: it's not really working.. :(

Can anyone help?