小问题,先答先得(100分)

  • 主题发起人 主题发起人 谭俊峰
  • 开始时间 开始时间

谭俊峰

Unregistered / Unconfirmed
GUEST, unregistred user!
在PChar字串中查找指定字串的API函数是什么?
 
无人知啊?
 
var<br>&nbsp; p: integer;<br>&nbsp; s: pchar;<br>begin<br>&nbsp; s := '1122334455';<br>&nbsp; p :=Pos('23',s);<br>&nbsp; showmessage(inttostr(p))<br>end;
 
function Pos(Substr: string; S: string): Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;子串 &nbsp; &nbsp; &nbsp; &nbsp;目标串 &nbsp; &nbsp; &nbsp; &nbsp; 子串在目标串中的起始位置<br>function StrPos(const Str1, Str2: PChar): PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标串 &nbsp; &nbsp; &nbsp;子串 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 指向子串在目标串中的头一个字符<br>祝顺利
 
如果要找a,在‘a.....a......a'中的位置,你可<br>var<br>&nbsp; stringlast,stringfirst:string;<br>&nbsp; p:integer;<br>begin<br>&nbsp; stringlast := 'a.....a......a';<br>&nbsp; strfirst &nbsp; :='';<br>&nbsp; p := Pos('a',stringlast);<br>&nbsp; while p&lt;&gt;0 do<br>&nbsp; begin<br>&nbsp; &nbsp; stringfirst := stringfirst+Copy(stringlast,1,p);<br>&nbsp; &nbsp; stringLast := Copy(stringlast,p+1,length(stringlast)-length(stringfirst));<br>&nbsp; &nbsp; p := Pos('a',stringlast);<br>&nbsp; end;<br>end;
 
用StrPos函数
 
非常感谢
 
后退
顶部