How to parse a CString? - Programmer

This is a discussion on How to parse a CString? - Programmer ; I'm trying to determine the best way to parse a CString. Basically, I am going to be getting an input of a URL, with a value at the end that is a number. I am trying to figure out how ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: How to parse a CString?

  1. How to parse a CString?

    I'm trying to determine the best way to parse a CString. Basically, I
    am going to be getting an input of a URL, with a value at the end that
    is a number. I am trying to figure out how to dispose of EVERYTHING
    in the string, exept for the numbers.

    The URL will look something like this.

    http://www.domain.com/file.html?Question=DR1234567

    All I want is to perform some function on that string that returns
    JUST the numbers.

    Ohh and, the URL may, or may not always be the same, so I can't just
    do a CString::Right on it.. :-(

    I figure this would require a regexp but I can't seem to figure out a
    good library to use, or how to use it.

    You know something like.

    CString url = "http://www.domain.com/file.html?Question=DR1234567
    url.Remove( RegExp("[^0-9]"), "" );
    ASSERT( url == "1234567 );

    Of course, there isn't anything (that I know of) equal to the "RegExp"
    in the above code.

    Any ideas?

    Thanks in advance!!

  2. Re: How to parse a CString?


    "Ryan J. Geyer" wrote in message
    news:bcefb87e.0311101807.12105e4e@posting.google.c om...

    > CString url = "http://www.domain.com/file.html?Question=DR1234567
    > url.Remove( RegExp("[^0-9]"), "" );
    > ASSERT( url == "1234567 );
    >


    pseudocode something like this:

    CString csResult = "";

    LPSTR lp1 = csResult.GetBufferSetLength(url.GetLength());

    LPCSTR lpc1 = (LPCSTR)url;

    while(*lpc1)
    {
    if(*lpc1 >= '0' && *lpc1 <= '9')
    *(lp1++) = *lpc1;

    lpc1++;
    }

    *lp1 = 0;
    csResult.ReleaseBuffer(-1);



    That would just about do it.




  3. Re: How to parse a CString?

    Thanks a million Bob!

    That worked perfectly.

    I'll have to tear it apart and make sure I understand it, but, for
    now, it's working, and I'm happy. :-)

    "Big Bad Bob" wrote in message news:...
    > "Ryan J. Geyer" wrote in message
    > news:bcefb87e.0311101807.12105e4e@posting.google.c om...
    >
    > > CString url = "http://www.domain.com/file.html?Question=DR1234567
    > > url.Remove( RegExp("[^0-9]"), "" );
    > > ASSERT( url == "1234567 );
    > >

    >
    > pseudocode something like this:
    >
    > CString csResult = "";
    >
    > LPSTR lp1 = csResult.GetBufferSetLength(url.GetLength());
    >
    > LPCSTR lpc1 = (LPCSTR)url;
    >
    > while(*lpc1)
    > {
    > if(*lpc1 >= '0' && *lpc1 <= '9')
    > *(lp1++) = *lpc1;
    >
    > lpc1++;
    > }
    >
    > *lp1 = 0;
    > csResult.ReleaseBuffer(-1);
    >
    >
    >
    > That would just about do it.


  4. Re: How to parse a CString?

    "Ryan J. Geyer" wrote in message
    news:bcefb87e.0311111041.61ff2a2d@posting.google.c om...
    > Thanks a million Bob!
    >
    > That worked perfectly.
    >
    > I'll have to tear it apart and make sure I understand it, but, for
    > now, it's working, and I'm happy. :-)
    >


    Would something like the following URL ever happen?
    http://www.domain1.com/file3.html?Question=DR1234567

    The algoithm below would get the 1 after domain and the 3 after file. Just
    a thought.
    Also is there always a "=" before the number? If so, maybe find the "="
    with CString::Find() then parse from there.

    dave h


    > "Big Bad Bob" wrote in message

    news:...
    > > "Ryan J. Geyer" wrote in message
    > > news:bcefb87e.0311101807.12105e4e@posting.google.c om...
    > >
    > > > CString url = "http://www.domain.com/file.html?Question=DR1234567
    > > > url.Remove( RegExp("[^0-9]"), "" );
    > > > ASSERT( url == "1234567 );
    > > >

    > >
    > > pseudocode something like this:
    > >
    > > CString csResult = "";
    > >
    > > LPSTR lp1 = csResult.GetBufferSetLength(url.GetLength());
    > >
    > > LPCSTR lpc1 = (LPCSTR)url;
    > >
    > > while(*lpc1)
    > > {
    > > if(*lpc1 >= '0' && *lpc1 <= '9')
    > > *(lp1++) = *lpc1;
    > >
    > > lpc1++;
    > > }
    > >
    > > *lp1 = 0;
    > > csResult.ReleaseBuffer(-1);
    > >
    > >
    > >
    > > That would just about do it.





    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

+ Reply to Thread