截取111*111*111中三个111(20分)

B

boy2002

Unregistered / Unconfirmed
GUEST, unregistred user!
如何截取111*111*111中三个111,中间两个是乘号,即星号,用pos可不可以判断出第二个
乘号,请提供办法和程序,多谢
 
可以,先找到第一个*,分离第一个111,删除这个*,在找到第二个*,分离第二个111...
 
ooooooooooo
 
-------不好意思,刚才看成删除指定字符了。看看这个:
procedure TForm1.Button1Click(Sender: TObject);
var
Src,Str1,SpChar:String;
begin
SpChar:='*';
Src:='111*1211*11111';
Src:=Src+SpChar;
while Pos(SpChar,Src)>0 do
begin
Str1:=Copy(Src,1,Pos(SpChar,Src)-length(SpChar));
Delete(Src,1,Pos(SpChar,Src));
showmessage(Str1);
end;
end;
 
ResultString:= '';
while W>0 do
begin
W:=pos(Edit2.Text,SourceString);
ResultString:=ResultString+Copy(SourceString,1,w-1)+edit3.Text;
SourceString := Copy(SourceString,W+1,Length(SourceString));
end;
ResultString:= ResultString+SourceString;
 
第一個用*, 第二個用其他符號不就可以解決問題啦.
 
var
s:array[1..3]of string;
a,c:byte;
begin
ss:='111*111*111';
c:=1;
for a:=1 to 3 do begin
s[a]:=copy(ss,c,3)
c:=c+4;
end;
end;
 
or:
var
s:array[1..3]of string;
a:byte;
begin
ss:='111*111*111';
for a:=1 to 3 do s[a]:=copy(ss,4*a-3,3)
end;
 
To form2:
他只是舉個例子, 不一定是111的, 如果是其他怎麼辦, 寫程式不能寫死的, 要活, 這是在寫
一個function, 應該放在甚麼地方都可以用才行的.
 
flist:tstrings;
s:string;
s:='111*111*111';
extractstrings([*],[' '],s,flist);
 
我写的C++的函数,你修改一下
/*
Description: this function is Parse Strings use Delimiter,Delimiter default
is "$"

function: ParseStrings
parameter:
List : Parse Strings array
strSource: string source
Delimiter: Parse character
return :bool,Parse success is true ,else false

*/
bool __fastcall TfrmMain::parseStrings(TStringList * List,AnsiString strSource,
AnsiString Delimiter="$")
{
//分割用 Delimiter (默认是$)分开的字符串,并将分开的字符串保存到数组List中
if((List==NULL)||strSource.Length()<1) return false;
List->Clear();
int iEnd=0,iLength=0;
iLength=strSource.Length();
AnsiString strTemp;
iEnd=strSource.Pos(Delimiter);
if(iEnd>0)
{
do
{
iEnd=strSource.Pos(Delimiter);
if(iEnd>0)
{
strTemp=strSource.SubString(1,iEnd-1);
List->Add(strTemp);
strSource=strSource.SubString(iEnd+1,iLength-iEnd);
}
else
{
if(strSource.Length()>0)
List->Add(strSource);
}
}
while(iEnd!=0);
}
else
{
if(strSource.Length()>0)
List->Add(strSource);
}
return true;
}
//---------------------------------------------------------------------------
 
呵呵,谢谢,瞎胡闹一下
s:='111*111*111';
function kk(s:string):string;
var
a:integer;
begin
for a:=1 to length(s) do if s[a]='*' then s[a]=#10;
result:=s;
end;
memo1.text:=s;
 
多人接受答案了。
 
顶部