- 论坛徽章:
- 0
|
请问用sh,怎么能把一个变量中的中文乱码给删掉
字符 '~'的ascii码第二大.最大那个我不知道怎么输入. ,小于这个~的肯定是ASCII码.上面的sh好象不能处理小括号,叹号.最好还是用c来处理.
- #include <sys/types.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdio.h>
- #include <err.h>
- int main(argc,argv)
- int argc;
- char **argv;
- {
- char buff[BUFSIZ];
- char *p=buff;
- int nread=-1;
- if(argc==2)
- strncpy(buff,argv[1],BUFSIZ);
- else{
- if((nread=read(STDIN_FILENO,buff,BUFSIZ))<0)
- err(1,"read");
- buff[nread]=0;
- }
- for(;*p;p++)
- if(isascii(*p))
- putc(*p,stdout);
- exit(0);
- }
复制代码 |
|