':'
是字符ASCII码, ":"
是字符串
printf("1. ':' c==[%c], d==[%d], sizeof=[%d]\n",':',':',sizeof(':'));
printf("2. \":\" c==[%c], s==[%s], d==[%d], sizeof=[%llu]\n", ":",":",":",sizeof(":"));
printf("\n");
char a1=':';
char *a2=":";
printf("a1==':' c==[%c], d==[%d], sizeof=[%d]\n",a1,a1,sizeof(a1));
printf("a2==\":\" c==[%c], s==[%s], d==[%d], sizeof=[%d]\n", a2,a2,a2,sizeof(a2));
printf("\n");
printf("a2==\":\" c==[%c], d==[%d], sizeof=[%d]\n", *a2,*a2,sizeof(*a2));
1. ':' c==[:], d==[58], sizeof=[4]
2. ":" c==[], s==[:], d==[4210688], sizeof=[2]
a1==':' c==[:], d==[58], sizeof=[1]
a2==":" c==[], s==[:], d==[4210688], sizeof=[8]
a2==":" c==[:], d==[58], sizeof=[1]
C 语言
方法一
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* strdel(char* in_str,char del_x)
{
char *p;
char *out_str=(char *)malloc(strlen(in_str));
char *q=out_str;
for(p=in_str;*p!='\0';p++)
{
if(*p!=del_x)
{
*q=*p;
q++;
}
}
*q=*p;
return out_str;
}
int main()
{
char in_str[64];
strcpy(in_str,"00:0c:29:c0:26:12");
printf("in_str=[%s]\n",in_str);
char *out_str=strdel(in_str,':');
printf("out_str=[%s]\n",out_str);
printf("Hello World!------------------------\n");
return 0;
}
in_str=[00:0c:29:c0:26:12]
out_str=[000c29c02612]
Hello World!------------------------
方法二
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void strdel(char* in_str,char del_x)
{
char *p;
char *q;
for(p=in_str,q=in_str;*p!='\0';p++)
{
if(*p!=del_x)
{
*q++=*p;
}
}
*q=*p;
}
int main()
{
char in_str[64];
strcpy(in_str,"00:0c:29:c0:26:12");
printf("in_str=[%s]\n",in_str);
strdel(in_str,':');
printf("out=[%s]\n",in_str);
printf("Hello World!------------------------\n");
return 0;
}
in_str=[00:0c:29:c0:26:12]
out=[000c29c02612]
Hello World!------------------------
方法三
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *get_str(char *str)
{
char *pch;
char *ret_str=(char *)calloc(0,strlen(str));
pch = strtok(str, ":");
while (pch != NULL)
{
strcat(ret_str,pch);
pch = strtok(NULL, ":");
}
return ret_str;
}
int main()
{
char str[] = "00:0c:29:c0:26:12";
char *ret_str;
ret_str = get_str(str);
printf("[%s]\n", ret_str);
return 0;
}
C++
方法四
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
char *in_str="00:0c:29:c0:26:12";
std::string str(in_str);
str.erase(std::remove(str.begin(), str.end(), ':'), str.end());
std::cout << str << std::endl;
cout << "Hello World!---" << endl;
return 0;
}
000c29c02612
Hello World!---
方法五
QString str = "00:0c:29:c0:26:12";
QStringList list = str.split(":");
qDebug()<<list;
QString ret_str = list.join("");
qDebug()<<ret_str;
QStringList list2 = {"a", "b", "c"};
QString ret_str2=list2.join("-");
qDebug()<<ret_str2;