可以直接提取出所有的字母,之后根据实际需要获取到相应的字母即可。
代码如下:
#include <iostream>
#include <string>
using namespace std;
void main()
{
int i;
string str;
getline(cin,str);
int cnt[2][26]={0};
for(i=0;str[i]!='\0';i++)
{
if(str[i]>='A' && str[i]<='Z')
cnt[0][str[i]-'A']++;
else if(str[i]>='a' && str[i]<='z')
cnt[1][str[i]-'a']++;
}
for(i=0;i<26;i++)
if(cnt[0][i])
cout<<char('A'+i)<<':'<<cnt[0][i]<<endl;
for(i=0;i<26;i++)
if(cnt[1][i])
cout<<char('a'+i)<<':'<<cnt[1][i]<<endl;
}
用正则表达式。下面是一个例子:
public class A{
public static void main(String[] args){
String match1 = "asdzxc";
String match2 = "asdzxc";
String match3 = "asd @anthing@ zxc";
String NOTmatch1 = "asdxc";
String NOTmatch2 = "";
String NOTmatch3 = "asdzxczx";
//////////////////////////////////////
String regex = "^asdzxc$";
//////////////////////////////////////
Systemoutprintln(match1matches(regex));//true
Systemoutprintln(match2matches(regex));//true
Systemoutprintln(match3matches(regex));//true
Systemoutprintln(NOTmatch1matches(regex));//false
Systemoutprintln(NOTmatch2matches(regex));//false
Systemoutprintln(NOTmatch3matches(regex));//false
}
}
以上就是关于c++已经是字符串string了,怎么具体提取其中的某个字母全部的内容,包括:c++已经是字符串string了,怎么具体提取其中的某个字母、java中如何在一个string中找出所有形如asd……zxc的字符串、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)