如何在字串中找出特定字??? |
答題得分者是:syntax
|
TTS
初階會員 發表:72 回覆:66 積分:27 註冊:2003-05-06 發送簡訊給我 |
|
AB
高階會員 發表:166 回覆:262 積分:125 註冊:2003-08-21 發送簡訊給我 |
|
huangeider
高階會員 發表:288 回覆:492 積分:231 註冊:2003-02-26 發送簡訊給我 |
用pos涵數
Delphi syntax: function Pos(Substr: string; S: string): Integer; Description In Delphi, Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions. Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero. The PosEx function is similar to Pos, but provides additional features and can be used in C code. 例如
if pos('向','物件導向討論區')>0 then
showmessage('找到了'); 「堅持」從洗馬桶做起
Aric
|
TTS
初階會員 發表:72 回覆:66 積分:27 註冊:2003-05-06 發送簡訊給我 |
|
cashxin2002
版主 發表:231 回覆:2555 積分:1937 註冊:2003-03-28 發送簡訊給我 |
您好! Pos函數傳回的是一個數值, 如果回傳的數值大于0, 則表示在字串中找到子字串, 其接受String形態, 範例如下:
Var S : String; I : Integer; begin S := ' Delphi is good '; While Pos(' ', S) > 0 do begin I := Pos(' ', S); S[I] := '_'; end; ShowMessage(S); end; //以上程式碼會將' Delphi is good 'String字串改成'_Delphi_is_good_'另外還有一個函數StrPos, 也可尋找子字串在字串中的位置, 但只接受PChar形態, 回傳PChar形態, 範例如下: Const P1 : PChar = 'Delphi is good'; P2 : PChar = 'is'; Var ReturnPoint : PChar; begin ReturnPoint := StrPos(P1, P2); if ReturnPoint = nil then ShowMessage('找不到指定的字串' P2) else ShowMessage(P2 '出現在第' IntToStr(RetrunPoint-P1) '個字'); end;參考看看! ===================== 努力,相信會獲得美麗! 忻晟
------
忻晟 |
huangeider
高階會員 發表:288 回覆:492 積分:231 註冊:2003-02-26 發送簡訊給我 |
|
syntax
尊榮會員 發表:26 回覆:1139 積分:1258 註冊:2002-04-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |