小弟不懂vc, 求超简单代码

gxboy 2008-07-03 10:09:10
用vc写个正则, 很简单.就是用参数key去匹配scr. 要求就是完成下面GetValueByKey里面的代码. scr是unicode编码,里面还会有汉字. 输出(即outstr)必须是utf-8编码
-----------------------------------------
scr = <&QQ&>123456</&QQ&>
key = QQ
outstr = 123456

下面是函数定义

CString __stdcall GetValueByKey(const char *key,const char *scr,char *outstr )
{
}
...全文
142 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
flight_lcf 2008-07-03
  • 打赏
  • 举报
回复
刚写了点,可能有不足的地方,请自己在修正一下吧。

bool GetValueByKey(const TCHAR *pKey,const TCHAR *pScr,TCHAR **ppOutstr )
{
if (NULL == ppOutstr)
{
return false;
}

int iKeyLen = _tcslen(pKey);

const TCHAR* pStart = NULL;
pStart = _tcsstr(pScr,pKey);
if (pStart == NULL)
{
return false;
}
pStart = pStart + iKeyLen + 2;

const TCHAR* pEnd = NULL;
pEnd = _tcsstr(pStart,pKey);
if (pEnd == NULL)
{
return false;
}
pEnd = pEnd - 3;

long len = pEnd - pStart + 1;

*ppOutstr = new TCHAR[len];
memset(*ppOutstr, 0, len * sizeof(TCHAR) );
_tcsncpy(*ppOutstr, pStart,len-1);
return true;
}
//如下是调用
TCHAR* pScr = _T("scr = <&QQ&>123456</&QQ&>");
TCHAR* pKey = _T("QQ");
TCHAR* pOut = NULL;
bool bGet = GetValueByKey(pKey, pScr, &pOut);
if (pOut != NULL)
{
delete []pOut;
pOut = NULL;
}
hua_yang 2008-07-03
  • 打赏
  • 举报
回复
http://www.cnblogs.com/anjou/archive/2007/03/20/681744.html

参考一下
奉海 2008-07-03
  • 打赏
  • 举报
回复
char cOutStr[1024];
GetValueByKey("QQ","<&QQ&>1234567<&QQ&>",cOutStr);
AfxMessageBox(cOutStr);

CString GetValueByKey(const char *key, const char *scr, char *outstr)
{
CString strTempKey;
CString strTempScr;
CString strTempOutStr;
strTempKey.Format("<&%s&>",key);
strTempScr.Format("%s",scr);
int nStartPos = strTempScr.Find(strTempKey,0);
int nEndPos = strTempScr.Find(strTempKey,nStartPos+1);
strTempOutStr = strTempScr.Mid(nStartPos + strTempKey.GetLength(),nEndPos-nStartPos - strTempKey.GetLength());
strcpy(outstr,strTempOutStr);
return strTempOutStr;
}
qaz2008 2008-07-03
  • 打赏
  • 举报
回复
upup
gxboy 2008-07-03
  • 打赏
  • 举报
回复
我没有时间看,大家帮帮我,我希望直接把你们写的代码复制过来就可以用
DarknessTM 2008-07-03
  • 打赏
  • 举报
回复
LZ还是看看MSXML吧,可能适合你
scq2099yt 2008-07-03
  • 打赏
  • 举报
回复
up
gxboy 2008-07-03
  • 打赏
  • 举报
回复
我晕,我在求助啊.相当于完形填空
菜牛 2008-07-03
  • 打赏
  • 举报
回复
为什么要按你的需求写出这里的代码呢?
gxboy 2008-07-03
  • 打赏
  • 举报
回复
CString __stdcall GetValueByKey(const char *key,const char *scr,char *outstr )
{
//按我的需求请写出这里的代码
//这两个参数: key = QQ, scr = <&QQ&>123456</&QQ&>, 那么outstr输出就是123456,就是说用正则或字符串处理的方式用key去匹配scr里的数据,最终将得到的值赋outstr
}
闪破风浪 2008-07-03
  • 打赏
  • 举报
回复
啥意思?
zoulie 2008-07-03
  • 打赏
  • 举报
回复
。。。。。。。。。。。。。。。。。
gxboy 2008-07-03
  • 打赏
  • 举报
回复
谢谢,但OutValue必须是utf-8的编码啊. 现在得出来的是unicode的编码,还需要一个转换哦.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧