64,637
社区成员
发帖
与我相关
我的任务
分享
int nPos = sUrl.Find(sParam);
if(nPos >= 0)
{
int nLen1 = sParam.GetLength();
if(sUrl.GetAt(nPos+nLen1) == '=')
{
int nLen2 = sUrl.GetLength();
return atoi(sUrl.Right(nLen2 - nPos - nLen1 -1));
}
}
return -1;
#include <string>
#include <map>
using namespace std;
typedef std::map<string, string> MAPSTR;
bool GetUrlParamValue(char* vURL, MAPSTR* vParamList)
{
if(0 == vURL) return false;
if(0 == vParamList) return false;
string tURL = vURL;
int tPos1 = tURL.find("?");
if(-1 == tPos1)
return true;
while(true)
{
tURL = tURL.substr(tPos1+1);
tPos1 = tURL.find("&");
int tPos2 = tURL.find("=");
if(-1 == tPos1) break;
if(-1 == tPos2) break;
string tParam = tURL.substr(0, tPos2);
string tValue = tURL.substr(tPos2+1, tPos1-tPos2-1);
vParamList->insert(std::make_pair(tParam, tValue));
}
return true;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char sU[]="http://127.0.0.1/forum.jsp?tid=123&fid=1";
int getUrlParamValue(char *sUrl,char *sParam) {//不是数或找不到sParam返回0
char s[1024],*p,a[80];
int L;
p=strchr(sUrl,'?');
if (!p) return 0;
strncpy(s,p,1023);s[1023]=0;
s[0]='&';
a[0]='&';
strncpy(a+1,sParam,77);a[78]=0;
strcat(a,"=");
L=strlen(a);
p=strstr(s,a);
if (!p) return 0;
return atoi(p+L);
}
int main() {
printf("%d,%d,%d\n",getUrlParamValue(sU,"tid"),getUrlParamValue(sU,"fid"),getUrlParamValue(sU,"zid"));
return 0;
}
//123,1,0