以前只是简单是使用sscanf,却没发现其还有如此强大的功能
char str0[100],str1[100],str2[100],str3[100];
sscanf("abcde abc 123 aaa","%s %s %s %s",str0,str1,str2,str3);
结果:str0="abcde" str1="abc" str2 = "123" str3="aaa"
sscanf("abcde abc 123 aaa","abc%s %s %*d %s",str0,str1,str3);
结果:str0="abcde" str1="abc" str3="aaa"
sscanf("abc123 efg456","%4s",str0);
结果:str0="abc1"
sscanf("abc123 efg456a4","%[a-z 1-5]",str0);
结果:str0="abc123 efg45"
sscanf("abc123 efg456a4","%[a-z1-5]",str0);
结果:str0="abc123"
sscanf("ABCTabcZ123 efg456","%[A-P]",str0);
结果:str0="ABC"
sscanf("abc 12345","%[^ ]",str0);
结果:str0="abc"
sscanf("abc 12345","%[^4]",str0);
结果:str0="abc 123"
sscanf("fdaBs 52aB1asdf","%[^4-0]",str0);
结果:str0="fdaBs 5"
sscanf("abc 12345","%[^ ]%[^3]",str0,str1);
结果:str0="abc" str1="12"
sscanf("abc301abc2345","%*[^9-0]%s",str0);
结果:str0="301abc2345"
sscanf("bca@123efg4@5abc","%*[^@]@%[^@]",str0);
结果:str0="123efg4"
posted on 2009-12-03 16:07
我风 阅读(876)
评论(0) 编辑 收藏 引用