[两个指针]删除字符串中指定的字符
2016-10-31 01:55
211 查看
删除字符串中指定的字符
输入 char *a = "abc123";
char *del = "a13";
利用两个字符指针的方式,pslow,pfast;
char *pslow,*pfast;
两个指针一开始都指向字符串的开始位置;
pfast开始遍历字符串,
if(*pfast==指定字符){////这里疑惑的地方就是,pslow什么时候向前滑行
将pfast所指字符,移到pslow的位置(就是赋值操作,*pslow = *fast)
pslow++;
pfast++;
}else{
pfast++;
}
///==================
输入 char *a = "abc123";
char *del = "a13";
利用两个字符指针的方式,pslow,pfast;
char *pslow,*pfast;
两个指针一开始都指向字符串的开始位置;
pfast开始遍历字符串,
if(*pfast==指定字符){////这里疑惑的地方就是,pslow什么时候向前滑行
将pfast所指字符,移到pslow的位置(就是赋值操作,*pslow = *fast)
pslow++;
pfast++;
}else{
pfast++;
}
///==================
#include <iostream> #include <stdio.h> #include <cstdio> #include <string> #include <string.h> #include <vector> #include <map> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <list> #include <limits.h> #include <set> //#include "xiaozhao.h" #include <numeric> #include <bitset> #include <iomanip> #include <queue> #include <math.h> #include <sstream> #include <stdio.h> #include <list> #include <stack> using namespace std; char TheArray[256]; void InitTheArray(const char* p){ while('\0'!=*p){ TheArray[*p++] = 1; } } void ProcessTheString(char *szDestination){ char *pFast; char *pSlow; pFast = pSlow = szDestination; while('\0'!=*pFast){ if(0==TheArray[*pFast]){ *pSlow=*pFast; pSlow++; pFast++; }else{ pFast++; } }///while *pSlow = '\0'; }///Process int main() { //Cxiao c; //c.test(); //freopen("input.txt", "r", stdin); char szDes[] = "they are students."; char szFind[] = "aeiou"; InitTheArray(szFind); ProcessTheString(szDes); printf("%s\n",szDes); return 0; }
相关文章推荐
- Exe7 删除字符串中指定的字符 (还有有问题——指针的问题)
- 字符串处理的两个问题:删除指定字符,删除相邻相同的字符
- 利用替换字符串的函数StringReplace删除字符串中指定的字符或字符串
- 数组和字符串操作(C#) 1、从字符串中删除指定字符
- 删除字符串中指定字符
- 删除字符串中指定的字符形成字符串
- 程序员面试指南(第六章) 数组和字符串(C#版) 2.从字符串中删除指定的字符
- 【我解C语言面试题系列】011 删除指定字符串的相应字符
- 从键盘输入一个字符串与一个指定字符,将字符串中出现的指定字符全部删除
- C语言删除字符串中的指定字符,字符串连接
- 【我解C语言面试题系列】010 从相应位置开始删除指定字符串的相应个字符
- 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符
- 删除字符串最后一个指定的字符
- [转载]c删除字符串中指定字符
- 删除字符串中首次出现的指定字符
- substring() 方法用于提取字符串中介于两个指定下标之间的字符。
- 【csdn题集】删除字符串中指定字符
- VB 在字符串增加内容与删除指定个数字符
- 删除 字符串中‘*’号 两端的除外。指针h、p分别指向第一个和最后一个字符
- 【我解C语言面试题系列】011 删除指定字符串的相应字符