查找字符串中的单词并替换
来源:互联网 发布:淘宝抢购时间 编辑:程序博客网 时间:2024/06/05 11:18
/* The string is: To do or not to do, It is a question! Enter your want to find a character string: not Enter you want to replace a character string: and To do or not to do, It is a question! To do or and to do, It is a question! 替换的单词必须与原单词长度相同,长度不同的情况实例如下: The string is: To do or not to do, It is a question!Enter your want to find a character string: doEnter you want to replace a character string: killTo do or not to do, It is a question!Tokil or not tokil, It is a question! */#include <stdio.h>#include <string.h>char * Find(char *, const char *, const char *, int);void Replace(char *, const char *, int);int main(void) { int lenB = 4, lenC = 4, ch, i; char a[] = "To do or not to do, It is a question!"; char b[lenB]; char c[lenC]; printf("Enter your want to find a character string: "); for (i = 0; (ch = getchar()) != '\n'; i++){ if (i < lenB) b[i] = ch; else printf("Not enough space, The character stirng is too long !"); } printf("Enter you want to replace a character string: "); for (i = 0; (ch = getchar()) != '\n'; i++){ if (i < lenC) c[i] = ch; else printf("Not enough space, The character stirng is too long !"); } printf("%s\n", a); Find(a, b, c, lenC - 1); printf("%s", a); return 0;}char * Find(char * a, const char * b, const char * c, int cLen){ char * pApear = NULL; const char * pB; while (*a++){ for (pB = b; *pB; pB++){ if (*a != *pB) break; else a++; } if (*pB == '\0'){ pApear = a; Replace(a-1, c, cLen-1); } } return pApear;}void Replace(char * a, const char * c, int cLen){ while (cLen > -1) *a-- = c[cLen--]; return;}
0 0
- 查找字符串中的单词并替换
- 字符串查找并替换
- VB查找并替换WORD文档中的字符串
- 查找文件并替换字符串
- 六章练习:查找一段字段中的单词(不分大小写),并替换。
- 查找并替换字符串的脚本
- awk条件查找字符串并进行替换
- PHP查找字符串中的最长单词
- 字符串替换新单词
- 如何从指定字符串中查找并替换字符串?
- C++字符串中查找子字符串并替换
- 查找并输出字符串中最长的单词
- 字符串:单词查找树
- 查找并替换
- objective-c 字符串查找并删除创建可变字符串重新设置字符串查找第一个并替换查找全部匹配的,并替换
- linux查找当前目录下包含某一单词的所有文件并进行替换
- 实现单词替换(非word中的字符串替换,有点难度)
- java字符串查找替换
- HDU 2821 DFS
- 编译Hadoop source code
- 有向图的强连通分量的tarjan算法总结
- 运用Autoconf和Automake生成Makefile 2
- 采用SharedPreferences保存用户偏好设置参数
- 查找字符串中的单词并替换
- hdu 5396 区间dp+组合
- poj 1396 All in All 字符串处理,短小精悍的题目
- 【学习笔记】堆、栈、自由存储区、全局/静态存储区和常量存储区
- C/C++ 中的特殊关键字:volatile, register, restrict, __attribute__
- 线程的生命周期
- Ceph Object Gateway与keystone集成
- hdu 5401 Persistent Link/cut Tree
- 自适应共振理论网络 ART