删除字符串中指定的一些字符
2017-03-05 16:38
281 查看
给定字符串“the c programming language ”,删除字符串中和“aeum”中字符相同的字符:
验证程序:
输出结果:
char * delChs(char * strScr, char * strDel) { if (strScr == NULL || strDel == NULL) { return NULL; } int flag[MAX_LEN] = {0}; while (*strDel != '\0') { flag[*strDel] = 1; ++strDel; } char * temp1 = strScr; char * temp2 = strScr; while (*temp2 != '\0') { if (!flag[*temp2]) { *temp1 = *temp2; ++temp1; } ++temp2; } *temp1 = '\0'; return strScr; }
验证程序:
int main() { char * str = "the c programming language"; char * del = "aeum"; char * temp = new char[strlen(str) + 1]; strcpy_s(temp, strlen(str) + 1, str); printf("%s\n", delChs(temp, del)); delete [] temp; temp = NULL; return 0; }
输出结果:
相关文章推荐
- 字符串的一些基本操作,复制,长度,子串查找,单词反转,比较,字符串反转,删除指定字符。
- 程序员面试指南(第六章) 数组和字符串(C#版) 2.从字符串中删除指定的字符
- 【csdn题集】删除字符串中指定字符
- 【我解C语言面试题系列】011 删除指定字符串的相应字符
- 从相应位置开始删除指定字符串的相应个字符
- 删除字符串最后一个指定的字符
- 数组和字符串操作(C#) 1、从字符串中删除指定字符
- 删除字符串中指定字符
- 【我解C语言面试题系列】010 从相应位置开始删除指定字符串的相应个字符
- 【我解C语言面试题系列】010 从相应位置开始删除指定字符串的相应个字符
- 字符串处理 删除指定字符
- 从键盘输入一个字符串与一个指定字符,将字符串中出现的指定字符全部删除
- 从字符串中删除一些字符
- 字符串处理的两个问题:删除指定字符,删除相邻相同的字符
- 删除字符串中指定的字符形成字符串
- 从字符串中删除指定字符
- VB 在字符串增加内容与删除指定个数字符
- ASP 删除字符串开始或/和末尾处指定字符(串)
- Java中如何从一个字符串中删除指定字符
- 从字符串的指定位置开始,删除指定长度字符