替换方法
来源:互联网 发布:泛雅网络教学平台 克隆 编辑:程序博客网 时间:2024/05/03 00:55
#include <iostream.h>
#include<string.h>
#define N 100
void th(char *p, char *pc, char *pt);
void main()
{
char str[N], cstr[N],tstr[N];
int s;
cout << "请输入字符串:/n";
cin.getline(str, N , '/n');
cout << "请输入要替换的字符串:/n";
cin.getline(cstr, N , '/n');
cout << "请输入替换的字符串:/n";
cin.getline(tstr, N , '/n');
s=strlen(tstr);
if(strlen(cstr) != strlen(tstr))
cout<<"替换长度不匹配!"<<endl;
else
th(str,cstr,tstr);
}
void th(char *p, char *pc, char *pt)
{
int i,j,g;
int num = 0;
char *ptrS;
char *a,*c;
a=p;
g=0;
while( *a != '/0' )
{
i = 0;
ptrS = pc;
while( 1 )
{
if( *ptrS == *(a + i) )
{ ptrS++; i++; j=g; }
else break;
if( *ptrS == '/0')
{ num++;
cout<<"查找到"<<num<<"个在第"<<j+1<<"个位置"<<endl;
c=pt;
while(1)
{
if(*c=='/0')
{ break; }
else
{
*(p+j)=*c;
j++;
c++;
}
}
break;
}
}
a++;
g++;
}
a=p;
while(1)
{
cout<<*a;
a++;
if(*a=='/0') break;
}
cout<<endl;
}
- 替换方法
- 方法替换
- 方法替换
- 替换任意的方法
- VIM常见替换方法
- js替换字符串方法
- 字符串替换方法
- vi全局替换方法
- Nsstring 替换方法
- jquery live() 替换 方法
- jquery live() 替换 方法
- vi全局替换方法
- JS 字符串替换方法
- vi全局替换方法
- Java字符串替换方法
- runtime 方法替换实现
- ajax替换iframe方法
- sizeWithFont方法过时替换
- Tomcat配置指南
- Linux下Shell基础知识简介
- tomcat配置虚拟主机
- 选择与放弃
- 61条面向对象设计的经验原则
- 替换方法
- iReaper_1.2_release 下载MSDN WebCast网络讲座的一个好工具
- 报表 css 圆角效果
- 喝水时间表
- 怎样对待女朋友
- MiddleGen-Hibernate的配置(oracle数据库)
- Automation 服务器不能创建对象的问题的解决方案大全
- 如何让DIV标签居中显示?
- C#实验[2]