fjh120 发表于 2011-2-27 16:41:27

请教VC字符串问题:如何将“\”后面的字符串提取出来?

现有一字符串:CString str="D:\\音乐\\刘德华\\刘德华.-..专辑.(MP3)\\刘德华 - 谁人知.mp3";

如何将“刘德华 - 谁人知.mp3”单独提取出来,请路过的朋友指点,非常感谢。

118139 发表于 2011-2-27 17:20:54

long nPos;
CString str;
str="D:\\音乐\\刘德华\\刘德华.-..专辑.(MP3)\\刘德华 - 谁人知.mp3";
nPos=str.ReverseFind('\\');
nPos=str.GetLength()-nPos-1;
AfxMessageBox(str.Right(nPos));

shark 发表于 2011-2-27 17:24:47

char * s = "D:\\音乐\\刘德华\\刘德华.-..专辑.(MP3)\\刘德华 - 谁人知.mp3";
char *p = s;
char d;
while (*p) p++;
p--;
while(*p !='\\' && p>s) p--;
if (p != s) { // found
   strcpy(d,p+1);// result in d.
}
else { //not found
   // you error process code
}

fjh120 发表于 2011-2-27 17:28:45

回复【2楼】118139
-----------------------------------------------------------------------

问题解决,感谢118139。。感谢ourdev。。

fjh120 发表于 2011-2-27 17:33:56

回复【3楼】shark
-----------------------------------------------------------------------

谢谢帮助。貌似有点复杂,看着指针就头晕。。

USBFD 发表于 2011-2-27 17:36:22

_tsplitpath()什么都有了
页: [1]
查看完整版本: 请教VC字符串问题:如何将“\”后面的字符串提取出来?