C chinachinamayso Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #1 有这样一个字符串“AAAA BBBBBB” A段的长度不定,B段的长度也不定,中间相隔一个空格,怎么取出A段来?
Z zqw0117 Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #3 var StrList: TStringList; begin StrList := TStringList.Create; try StrList.Text := ReplaceString('AAAAAA BBBBBB', ' ', #13#10, [rfReplaceAll]); for I:=0 to StrList.Count - 1 do ShowMessage('Line' + IntToStr(I+1) + ':' + StrList); finally StrList.Free; end; end;
var StrList: TStringList; begin StrList := TStringList.Create; try StrList.Text := ReplaceString('AAAAAA BBBBBB', ' ', #13#10, [rfReplaceAll]); for I:=0 to StrList.Count - 1 do ShowMessage('Line' + IntToStr(I+1) + ':' + StrList); finally StrList.Free; end; end;
C chinachinamayso Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #4 ReplaceString属于哪个类?
D david_jkl Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #5 str:='AAAA BBBBBB'; ss:=Copy(str,1,Pos(' ',str)-1);
Z zqw0117 Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #6 ReplaceString不属于任何类,是一个函数 如果兄弟编译不了,试着反过来,写StringReplace,呵呵,可能我把名字记反了
G goldensang Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #7 上面的两个方法都可以 var StrList: TStringList; I:integer; begin StrList := TStringList.Create; try StrList.CommaText :='AAAAAA BBBBBB';// 一般空格、Tab和',' 会自动换行 for I:=0 to StrList.Count - 1 do ShowMessage('Line' + IntToStr(I+1) + ':' + StrList); finally StrList.Free; end; I:=Pos(' ','AAAAAA BBBBBB'); ShowMessage(Copy('AAAAAA BBBBBB',1,I-1));
上面的两个方法都可以 var StrList: TStringList; I:integer; begin StrList := TStringList.Create; try StrList.CommaText :='AAAAAA BBBBBB';// 一般空格、Tab和',' 会自动换行 for I:=0 to StrList.Count - 1 do ShowMessage('Line' + IntToStr(I+1) + ':' + StrList); finally StrList.Free; end; I:=Pos(' ','AAAAAA BBBBBB'); ShowMessage(Copy('AAAAAA BBBBBB',1,I-1));
隐 隐士山人 Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-01 #8 //用牛刀杀鸡?用小刀就行了!!!!!!! //要在Uses 中加入 StrUtils (单元) procedure TForm1.BitBtn1Click(Sender: TObject); var s:string; begin s:='AAAAA BBBBBBBBBBB'; showmessage(LeftStr(S, Pos(' ', s)));// ' '中点开一个空格 end;
//用牛刀杀鸡?用小刀就行了!!!!!!! //要在Uses 中加入 StrUtils (单元) procedure TForm1.BitBtn1Click(Sender: TObject); var s:string; begin s:='AAAAA BBBBBBBBBBB'; showmessage(LeftStr(S, Pos(' ', s)));// ' '中点开一个空格 end;
B bbscom Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-02 #9 ShowMessage(LeftStr('AAAAA BBBBBBBBBBB', Pos(' ', 'AAAAA BBBBBBBBBBB')));
H happycyp Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-05 #11 ExtractStrings函数一个就可以搞定呀
风 风卷残月 Unregistered / Unconfirmed GUEST, unregistred user! 2007-03-05 #13 这样的问题自己搜下就可以解决的,有必要在这开贴嘛...........