CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    121

    Help I need help

    CString string= "http://home.microsoft.com?RID=Report1&Date=today";
    int len = string.GetLength();
    while(len>0)
    {
    int pos = string.Find("?");
    if(pos>0)
    {
    int i =0;
    CString URL = string.Mid(0, pos);
    int pos2 = string.Find("=");
    int pos3 = string.Find("&");
    CString string2 = string.Mid(pos2, 8);


    }
    }

    What I want is to find what is inbetween '=' & '&'. I can find "Report1" but than I can't find "today"

    If someone can show me what I'm doing wrong...

    Thank you


  2. #2
    Join Date
    Jun 1999
    Location
    Canada - Québec
    Posts
    273

    Re: Help I need help

    try like this :

    CString string= "home.microsoft.com?RID=Report1&Date=today";
    int pos = string.Find("?");
    if(pos>0)
    {
    CString URL = string.Mid(0, pos);
    string = string.Mid(pos);
    len = string.GetLength();
    while(len>0)
    {
    int pos2 = string.Find("=");
    int pos3 = string.Find("&");
    if (pos3 == -1)
    CString string2 = string.Mid(pos2, pos3);
    else
    CString string2 = string.Mid(pos2);
    string = string.Mid(pos3);
    len = string.GetLength();
    }
    }



    if i understand what you want to do... it will be ok..


  3. #3
    Join Date
    Jun 1999
    Location
    Canada - Québec
    Posts
    273

    Re: Help I need help

    sorry.. i make 1 error in last..
    now its good :

    CString string= "home.microsoft.com?RID=Report1&Date=today";
    int pos = string.Find("?");
    if(pos>0)
    {
    CString URL = string.Mid(0, pos);
    string = string.Mid(pos);
    len = string.GetLength();
    while(len>0)
    {
    int pos2 = string.Find("=");
    int pos3 = string.Find("&");
    if (pos3 != -1)
    {
    CString string2 = string.Mid(pos2, pos3);
    string = string.Mid(pos3);
    len = string.GetLength();
    }
    else
    {
    CString string2 = string.Mid(pos2);
    len = 0;
    }
    }
    }






  4. #4
    Join Date
    May 1999
    Location
    Seattle, WA USA
    Posts
    423

    Re: Help I need help

    CString string = "http://home.microsoft.com?RID=Report1&Date=today";
    int len = string.GetLength();
    if (len > 0) // use if instead of while, or we have an infinte loop
    {
    int pos = string.Find("?");
    if(pos>0)
    {
    int i =0;
    CString URL = string.Mid(0, pos);
    int pos2 = string.Find("=");
    int pos3 = string.Find("&");
    // use pos2 + 1, because CString's are 0
    CString string2 = string.Mid(pos2 + 1, pos3 - pos2 - 1); based
    int pos4 = string.ReverseFind('=');
    CString string3 = string.Right (len - pos4 - 1);
    }
    }

    To find the last part of the string (the "today" part), you just need to find the '=' and grap all the characters after that up to the end. I found the '=' sign by using CString::ReverseFind, & then took the remaining characters with CString::Right.

    If the code doesn't make sense to you, or if you have any more questions, send me a private message or just respond to this message.

    HTH
    --michael


  5. #5
    Join Date
    Apr 1999
    Posts
    121

    Re: Help I need help

    This works great for that string but what if a parameter was added such that
    CString string = "http://home.microsoft.com?RID=Report...y&Date2=today2";

    Thanks



  6. #6
    Join Date
    Jun 1999
    Location
    Canada - Québec
    Posts
    273

    Re: Help I need help

    loop like i said... but change values for .Mid()


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