📄 lineedit.h
字号:
//行操作
void print_str_line(char *str,PBigStr pstr)//打印含有str的所有行并且打印出行号
{
int i=1;
PBigStr node=pstr;
while (node->link!=NULL)
{
if (find_line(str,node)!=NULL)//查找符合条件的行
{
printf("The %d line:\n",i);
print_line(i,pstr);
}
node=node->link;
i++;
}
if (find_line(str,node)!=NULL)
{
printf("The %d line:\n",i);
print_line(i,pstr);
}
}
void delete_str_line(int p,char *str)//删除字符串str的下标为p的字符
{
int q,n=strlen(str);
for (q=p;q<n-1;q++)
str[q]=str[q+1];
str[n-1]='\0';
}
char *replace_line(char *prestr,char *nextstr,char *pc)//替换字符串pc中的prsstr为nextstr
{
int index,i=0;
char *temp;
char *newpc=(char *)malloc(80*sizeof(char));
PBigStr newnode=create_nullstr();
int pre=strlen(prestr);
int next=strlen(nextstr);
for (i=0;i<80;i++)
newpc[i]='\0';
temp=pc;
index=index_line(temp,prestr);
while (index>=0)
{
for (i=0;i<index;i++)
newpc=back_insert_char(newpc,temp[i]);//将prestr之前的字符插入到新串中
for (i=0;i<next;i++)
newpc=back_insert_char(newpc,nextstr[i]);//将nextstr插入到新串中
temp=&temp[pre+index];//定位到旧串的已经匹配的字符后面
index=index_line(temp,prestr);
}
if (temp[0]!='\0')
for (i=0;temp[i]!='\0';i++)
newpc=back_insert_char(newpc,temp[i]);
pc=newpc;
return pc;
}
PBigStr replace_n_line(int n,char *prestr,char *nextstr,PBigStr pstr)//替换第n行的prestr为nextstr
{
PBigStr temp,node,newnode=create_nullstr();
char *pc;
if (n<=0)
{
printf("Integer Error!\n");
return pstr;
}
if (n==1)
{
node=pstr;
pc=replace_line(prestr,nextstr,node->pc);//将替换后的字符串赋给临时串pc
insert_str(pc,newnode);//临时字符串插入到新结点中
temp=newnode;//将新结点连接到原表中
while (newnode->link!=NULL)
newnode=newnode->link;
newnode->link=node->link;
pstr=temp;
free(node);
return pstr;
}
node=locate_line(n,pstr);
if (node==NULL||node->link==NULL)
{
printf("Out of range!\n");
return pstr;
}
pc=replace_line(prestr,nextstr,node->link->pc);//将替换后的字符串赋给临时串pc
insert_str(pc,newnode);//临时字符串插入到新结点中
temp=newnode;;//将新结点连接到原表中
while (newnode->link!=NULL)
newnode=newnode->link;
newnode->link=node->link->link;
node->link=temp;
return pstr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -