如何傳回指定字串在某字串中的位置 |
答題得分者是:terrychen
|
Elsa-fen
一般會員 ![]() ![]() 發表:9 回覆:16 積分:5 註冊:2003-09-25 發送簡訊給我 |
|
Fishman
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi: 你可以使用
FindText 的指令,HELP 說明如下
procedure TForm1.Button1Click(Sender: TObject); begin FindDialog1.Position := Point(RichEdit1.Left RichEdit1.Width, RichEdit1.Top); FindDialog1.Execute; end; procedure TForm1.FindDialog1Find(Sender: TObject); var FoundAt: LongInt; StartPos, ToEnd: Integer; begin with RichEdit1 do begin { begin the search after the current selection if there is one } { otherwise, begin at the start of the text } if SelLength <> 0 then StartPos := SelStart SelLength else StartPos := 0; { ToEnd is the length from StartPos to the end of the text in the rich edit control } ToEnd := Length(Text) - StartPos; FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]); if FoundAt <> -1 then begin SetFocus; SelStart := FoundAt; SelLength := Length(FindDialog1.FindText); end; end; end;但你的需求,似乎用類似 procedure TForm1.Button14Click(Sender: TObject); begin Memo1.Clear; TRY Memo1.Lines.Delimiter := ' '; Memo1.Lines.DelimitedText := Edit5.Text; EXCEPT END; end;的方法,會更簡單點
------
Fishman |
terrychen
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:90 回覆:794 積分:501 註冊:2003-05-01 發送簡訊給我 |
|
Rain
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:236 積分:268 註冊:2003-02-17 發送簡訊給我 |
|
Elsa-fen
一般會員 ![]() ![]() 發表:9 回覆:16 積分:5 註冊:2003-09-25 發送簡訊給我 |
引言: 可以用ExtractStrings來分割字串、var S: string; SL: TStringList; begin S := '123456 7890'; SL := TStringList.Create; ExtractStrings([' '], [], PChar(S), SL); ShowMessage(SL.Text); SL.Free; end;謝謝Rain提供的資料...因為我是要做一個參數檔.. 檔案資料如: 20 /*test valu*/ 所以如果用您的方法...會將此字串切成 20 /*test value*/ 但...我只要切成 20,/*test valu*/ 2個就好了 |
Elsa-fen
一般會員 ![]() ![]() 發表:9 回覆:16 積分:5 註冊:2003-09-25 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |