Click to See Complete Forum and Search --> : Help I need help
Sophie
July 19th, 1999, 02:36 PM
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
ChristianM
July 19th, 1999, 02:51 PM
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..
ChristianM
July 19th, 1999, 02:55 PM
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;
}
}
}
chiuyan
July 19th, 1999, 03:00 PM
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
Sophie
July 19th, 1999, 03:14 PM
This works great for that string but what if a parameter was added such that
CString string = "http://home.microsoft.com?RID=Report1&Date=today&Date2=today2";
Thanks
ChristianM
July 19th, 1999, 03:23 PM
loop like i said... but change values for .Mid()
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.