1.拼接字符串
static char SEND_S[13] = {'A','T','+','C','I','P','S','E','N','D','=','1',','}; static char SEND_X[23] = {',','"','1','9','2','.','1','6','8','.','1','0','.','1','"',',','8','8','8','9',' ',' '}; static char COMMAND[99]; memset( COMMAND, 0, sizeof( COMMAND) ); strcat( COMMAND, SEND_S); strcat( COMMAND, SEND_X);
2.对比字符串
if( strstr(_udp_rece,"WIFI DISCONNECT") != 0 ) //wifi断开 { }
3.字符串转整型
int char_int( const char *cha ) //字符串转整型 { u8 data[8]={0,0,0,0,0,0,0,0}; int temp = 0,ret = 0; u8 num = 0,err = 0,i = 0,j=0; //位数 正负 while( *cha ) { if( ( *cha >= '0') && ( *cha <= '9' ) ) { data[num] = (*cha - '0'); num++; } if( *cha == '-' ) //负号 { err = 1; } cha++; } for( j = 0; j < num; j++ ) { temp = data[j]; for( i = num - j - 1; i>0 ; i-- ) { temp *= 10; } ret += temp; } if( err == 1 ) { ret = -ret; } return ret; }
4.整型转字符串
void itoa (int n,char *s) //整型转字符串 { char temp[10]; int i = 1,j = 0,sign = 0; memset( temp, 0 ,10 ); if( n < 0 )//记录符号 { n=-n;//使n成为正数 sign = -1; } do { temp[i++]=n%10+'0';//取下一个数字 } while ((n/=10)>0);//删除该数字 if(sign<0) { temp[i++]='-'; } temp[0]='