截取字符串


/***********************
清除掉圆括号()里面的字符
但是保留方括号[]里面的字
符(输入的字符串中括号成
对出现)
************************/
#include <iostream>
#include <string>

using namespace std;

static char * transChar(char *p)
{
static char temp[100];
int flag=0;//遇见'('flag=1,遇见')'flag=0.
int i=0;

for (;*p!='\0';p++)//遍历字符串
{
if (*p=='('||*p==']')
{
if (*p=='(')
flag=1;
if(*p==']')
p++;
for (;*p!=')'&&flag&&*p!='\0';p++)//去除括号内的字符串
if (*p=='['||*p==']')
break;
}

for (;*p=='('||*p==')'||*p=='['||*p==']';p++)
{
if(*p==')')
flag=0;
}
temp[i]=*p;
i++ ;
}
temp[i]=0;
return temp;
}

void main()
{
char s1[50];
cout<<"please enter a string"<<endl;
cin>>s1;
strcpy(s1,transChar(s1));
cout<<s1<<endl;
}

/************************************
输入:nihao(ashjkfa[Unblue2008]ashf)!
输出:nihaoUnblue2008!
************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值