贴一个我自己的分隔函数(有些函数历史悠久)<br> function str_dispart(str:string;var strS:TstringList;disStr:string):integer;<br> {将str按disStr 分开并放入strS}<br>和相关函数<br> procedure DelRepStr(var str:string;substr:string);<br> {删除str中连续重复为substr字符串,只保留一个}<br> procedure DelFirststr(var str:string;substr:string);<br> {删除str头部所有为substr的字符串}<br>function str_dispart(str:string;var strS:TstringList;disStr:string):integer;<br>var<br> i,j:integer;<br> st,stt:string;<br>begin<br> strS.Clear;<br> stt:=str;<br> stt:=stt+disStr;<br> delRepStr(stt,disStr);//删除连续的分隔,只保留一个。<br> if stt=disStr then<br> begin<br> result:=0;<br> exit;<br> end;<br> delfirstStr(stt,disStr);//删除起始分隔。<br> //delendStr(str,disStr);//删除末尾分割。<br> j:=length(disStr);<br> i:=pos(disStr,stt);<br> while i<>0 do<br> begin<br> st:=copy(stt,0,i-1);<br> strS.add(st);<br> delete(stt,1,i+j-1);<br> i:=pos(disStr,stt);<br> end;//while i<>0 strings<br> result:=strS.count;<br> end;<br><br> procedure DelRepStr(var str:string;substr:string);<br> var<br> st:string;<br> i,j:integer;<br> begin<br> st:=substr+substr;<br> j:=length(substr);<br> i:=pos(st,str);<br> while i<>0 do<br> begin<br> delete(str,i,j);<br> i:=pos(st,str);<br> end;<br> end;<br>procedure DelFirststr(var str:string;substr:string);<br>var<br> st:string;<br> i:integer;<br>begin<br> i:=length(substr);<br> st:=copy(str,1,i);<br> while st=substr do<br> begin<br> delete(str,1,i);<br> st:=copy(str,1,i);<br> end;<br> end;<br>再来一个<br> function DelRepStr_Quotness(var s:string;substr:string):integer;<br> {删除str中连续重复为substr字符串,只保留一个引号内的不删,<br> 若引号孤独则返回孤独引号所在位置,否则返回0}<br>function DelRepStr_Quotness(var s:string;substr:string):integer;<br>var<br> st,st_leader,st_tmp:string;<br> pos_duble,pos_single:integer;<br> TorF:boolean;<br> begin<br> result:=0;<br> Torf:=True;<br> st_leader:='';<br> st:=s;<br> while TorF do<br> begin<br> pos_duble:=pos('"',st);<br> pos_single:= pos('''',st);<br> if (pos_duble>0) or (pos_single>0) then //两种引号至少有一个<br> if (pos_duble>0)and<br> ((pos_duble< pos_single) or (pos_single=0)) then //双引号在前 或只有双引号<br> begin<br> st_tmp:=copy(st,1,pos_duble);<br> DelRepstr(st_tmp,substr);<br> st_leader:=st_leader+st_tmp;<br> delete(st,1,pos_duble);<br> pos_duble:=pos('"',st);<br> if pos_duble=0 then //双引号不匹配<br> begin<br> s:= st_leader+st;<br> result:=length(st_leader)-1;<br> exit;<br> end; //end if pos_duble=0<br> st_tmp:=copy(st,1,pos_duble);<br> st_leader:=st_leader+st_tmp;<br> delete(st,1,pos_duble);<br> end //end if pos_duble< pos_single<br> else begin // 单引号在前或只有单引号<br> st_tmp:=copy(st,1,pos_single);<br> DelRepstr(st_tmp,substr);<br> st_leader:=st_leader+st_tmp;<br> delete(st,1,pos_single);<br> pos_single:=pos('''',st);<br> if pos_single=0 then //单引号不匹配<br> begin<br> s:= st_leader+st;<br> result:=length(st_leader)-1;<br> exit;<br> end; //end if pos_duble=0<br> st_tmp:=copy(st,1,pos_single);<br> st_leader:=st_leader+st_tmp;<br> delete(st,1,pos_single);<br> end //end if pos_duble> pos_single<br> else TorF:=false;<br> end; // end while<br> DelRepstr(st,substr);<br> st_leader:=st_leader+St;<br> s:= st_leader;<br> end;