循环读取每一个字符,再进行条件判断,分为大写英文字母、小写字母、数字、其他字符,分别输出upper letter、lower letter、digit、other character。把源程序复制一下
#include<stdlibh>
#include<stringh>
int main()
{
char ch[100];
int i;
int length;
printf("please input a string:\n");
scanf("%s",ch);
length=strlen(ch);
printf("the length is %d\n",length);
for(i=0;i<length;i++)
{
if(ch[i]<='Z' && ch[i]>='A')
{
printf("the %d character is upper letter\n",i+1);
}
else
{
if(ch[i]<='z' && ch[i]>='a')
{
printf("the %d character is lower letter\n",i+1);
}
else
{
if(ch[i]<='9' && ch[i]>='0')
{
printf("the %d character is digit\n",i+1);
}
else
{
printf("the %d character is other character\n",i+1);
}
}
}
}
return 0;
}
运行结果,如果有什么不明白的还可以问我
str2="PSAPAPFDF"
if instr(str2,str1)<>0 then
responsewrite("字符"&str1&"属于字符串"&str2)
end if使用字符串的IndexOf方法查找,找到返回正确的位置下标,未找到返回-1
举例:
string str = "我爱北京天安门";
int index = strIndexOf("爱");
if (index > -1)
{
ConsoleWrite("找到了");
}
else {
ConsoleWrite("未找到");
}
ConsoleRead();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)