去除字符串首尾空白字符:
static void ltrim(char *s)
{
char *p;
p = s;
while(*p == ' ' || *p == '\t'){*p++;}
strcpy(s,p);
}
static void rtrim(char *s)
{
int i;
i = strlen(s)-1;
while((s[i] == ' ' || s[i] == '\t') && i >= 0){i--;};
s[i+1] = '\0';
}
提取字符串中数字
int GetCharNum(char *s)
{
char Num[10] = {0};
int i = 0;
while (*s != '\0'){
if (*s >= '0' && *s <= '9'){
Num[i++] = *s;
}
s++;
}
return (atoi(Num));
}
截取字符串中两个字符中间字符串
char *p,*q;
char buff[20];
p = strchr(updateFile[j],':');
q = strrchr(updateFile[j],';');
memcpy(buff, p + 1, q - p - 1);
将16进制数据字符串转换成字符串
char buff[32];
for (x = 0; x < strlen(szDigest); x++) {
char buffer[1];
sprintf(buffer, "%.2X",(unsigned char)szDigest[x]);
strcat(buff,buffer);
}
将字符串转换成16进制
char str[100] = "EB4D67E8F2FCE45F613144876EF8D1B9";
char bin[50];
int i,v,L;
L=strlen(str);
for (i=0;i<L/2;i++) {
sscanf(str+i*2,"%2X",&v);
bin[i]=(char)v;
printf("%02X ",(unsigned char)bin[i]);
}