This topic has been archived. It cannot be replied.
-
工作学习 / 专业知识杂谈 / How to find the first and second letter of a stringI want find the first and second letter of a string,my string contains of 1-n characters,it could include non-letter characters in any position,but at less have one letters,if it contains only one letter,first letter and second letter are same.anyone could give me a better solution,any language,thanks
-xiangdang(大魏);
2006-7-2
{303}
(#3059284@0)
-
An example.#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char **argv) {
int i;
char *anystr="";
char ret[2];
for( i=0; i<strlen(anystr); i++ ) {
if( isalpha( anystr[i] ) ) {
ret[0] = anystr[i];
ret[1] = anystr[i];
break;
}
}
i++;
for( ;i<strlen(anystr); i++ ) {
if( isalpha( anystr[i] ) ) {
ret[1] = anystr[i];
break;
}
}
printf("result: [%c%c]\n", ret[0], ret[1]);
return 0;
}
-canadiantire(轮胎-cui bono?);
2006-7-4
{474}
(#3061258@0)
-
thanks,it's really help
-xiangdang(大魏);
2006-7-15
(#3081352@0)