如何得到这个字符串中两个()之间的字符串 问个c语言最基础的问题. string StrCom = str2.substr(0,4); //str2是字符串"(com45)"请问StrCom如何得到这个字符串中两个()之间的字符串? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string StrCom = str2.substr(1,5); CString str=_T("(com4)");str.Replace(_T("("),_T(""));str.Replace(_T(")"),_T("")); string StrCom = str2.substr(str2.Find('(') + 1,str2.Find(')') - str2.Find('(') - 1);安全点你可以判断下 Find的返回值 或者用3楼的 不过你要考虑"(sa(asad)as)"等等这些情况下该怎么处理 如果括号左右还有东西,就不支持了。大致这样就可以(假定字串是规则的,如果字串复杂,要加各种判断):#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());}如果是复杂的最好用正则表达式 有序链表合并的文图 SDI编程界面怎么办 winpcap文档中找不到PacketOpenAdapter函数解释 跪求一个访问冲突的问题 MFC单文档应用程序的视图分割,要实现简单的表态分割,左边为一树形结构,右边为ListView 寻求最快的检索办法(MSSQL),提意见也有分 如何读取access文件中的表结构?100分求源码 Wave OpenGL 源代码公布 -- 水波运动模拟和显示 问一个逻辑问题,大家帮忙想想 怎样在VC下调试带有指针操作的C程序?它总是出现一般保护错。 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());
}
如果是复杂的最好用正则表达式