问个c语言最基础的问题. string StrCom = str2.substr(0,4); //str2是字符串"(com45)"
请问StrCom如何得到这个字符串中两个()之间的字符串?
请问StrCom如何得到这个字符串中两个()之间的字符串?
解决方案 »
- 类的CString成员是否需要深拷贝?
- 怎么使用CButtonST加入到我自己的工程?
- 谁知道CZoomVew视图缩放源程序在哪里啊?
- 怎样通过EnumFontFamiliesEx得到字体文件名
- 子窗口要用到父窗口的函数各属性,最好的方法是什么!
- 关于全局变量和全局函数的问题
- 想研究一下代理服务器软件,哪位大虾知道那有代理服务器软件的源码和资料可下?
- KeI386AllocateGdtSelectors()这些未公开函数到底该怎么用?
- 使用CFile.Write写文件,报错的问题
- 太简单了,关于对VC++6.0集成开发环境设定的一个小问题。
- vc下登陆对话框中的密码怎么才能使它不是明文
- vc ocx 如何触发 网页的操作
str.Replace(_T("("),_T(""));
str.Replace(_T(")"),_T(""));
大致这样就可以(假定字串是规则的,如果字串复杂,要加各种判断):
#include <string>using namespace std;int main()
{
string xxx = "左边的(括号中的部分)右边的";
int nLeft = xxx.find("(");
int nRight = xxx.find(")");
string result = string(xxx.c_str() + nLeft + 1, nRight - nLeft - 1);
printf("%s\n", result.c_str());
}
大致这样就可以(假定字串是规则的,如果字串复杂,要加各种判断):
#include <string>using namespace std;int main()
{
string xxx = "左边的(括号中的部分)右边的";
int nLeft = xxx.find("(");
int nRight = xxx.find(")");
string result = string(xxx.c_str() + nLeft + 1, nRight - nLeft - 1);
printf("%s\n", result.c_str());
}
如果是复杂的最好用正则表达式