字符a在字符串的位置的函数?(100分)

  • 主题发起人 主题发起人 路远
  • 开始时间 开始时间

路远

Unregistered / Unconfirmed
GUEST, unregistred user!
AnsiIndexText的功能 返回字符串AText在字符串数组AValues中的位置<br>现。不行
 
pos<br>-----<br>procedure TForm1.Button1Click(Sender: TObject);<br>var i,ii:integer;<br>s,ss,sss:string;<br>begin<br>s:=memo1.Text; //s代表memo1.Text里的内容<br><br>i:=pos('%^',s);//%^的乞食位置<br>ii:=pos('^%',s);//^%的乞食位置<br>s:=copy(s,i+2,ii-i-2);//指定复制位置,因为‘^%’是两个字符,所以向后+2,<br><br>i:=pos('[',s); //[的乞食位置<br>ii:=pos(']',s);//]的乞食位置<br>ss:=copy(s,i+1,ii-i-1);//指定复制位置,因为‘[’是1个字符,所以向后+1,<br>memo2.Lines.Add(ss);//向MEMO2中添加一行,[]中的内容.如果只有一行就memo2.text:=ss;<br><br>i:=pos('(',s); //(的乞食位置<br>ii:=pos(')',s);//)的乞食位置<br>ss:=copy(s,i+1,ii-i-1); //指定复制位置,因为‘(’是1个字符,所以向后+1,<br>memo3.Lines.Add(ss); &nbsp;//向MEMO3中添加一行,()中的内容<br><br>i:=pos('{',s); //{的乞食位置<br>ii:=pos('}',s);//}的乞食位置<br>sss:=copy(s,i+1,ii-i-1); //指定复制位置,因为‘{’是1个字符,所以向后+1,<br>memo4.Lines.Add(sss); &nbsp;//向MEMO3中添加一行,{}中的内容<br>end;<br>
 
下面是大名鼎鼎的QStrings单元的两个函数,你直接拷贝过去就可以用了,不仅完全符合你<br>的要求,而且速度极快!<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1 &nbsp; &nbsp; &nbsp; &nbsp;: TForm1;<br><br>const<br>&nbsp; ToUpperChars: array[0..255] of Char =<br>&nbsp; &nbsp; (#$00,#$01,#$02,#$03,#$04,#$05,#$06,#$07,#$08,#$09,#$0A,#$0B,#$0C,#$0D,#$0E,#$0F,<br>&nbsp; &nbsp; &nbsp;#$10,#$11,#$12,#$13,#$14,#$15,#$16,#$17,#$18,#$19,#$1A,#$1B,#$1C,#$1D,#$1E,#$1F,<br>&nbsp; &nbsp; &nbsp;#$20,#$21,#$22,#$23,#$24,#$25,#$26,#$27,#$28,#$29,#$2A,#$2B,#$2C,#$2D,#$2E,#$2F,<br>&nbsp; &nbsp; &nbsp;#$30,#$31,#$32,#$33,#$34,#$35,#$36,#$37,#$38,#$39,#$3A,#$3B,#$3C,#$3D,#$3E,#$3F,<br>&nbsp; &nbsp; &nbsp;#$40,#$41,#$42,#$43,#$44,#$45,#$46,#$47,#$48,#$49,#$4A,#$4B,#$4C,#$4D,#$4E,#$4F,<br>&nbsp; &nbsp; &nbsp;#$50,#$51,#$52,#$53,#$54,#$55,#$56,#$57,#$58,#$59,#$5A,#$5B,#$5C,#$5D,#$5E,#$5F,<br>&nbsp; &nbsp; &nbsp;#$60,#$41,#$42,#$43,#$44,#$45,#$46,#$47,#$48,#$49,#$4A,#$4B,#$4C,#$4D,#$4E,#$4F,<br>&nbsp; &nbsp; &nbsp;#$50,#$51,#$52,#$53,#$54,#$55,#$56,#$57,#$58,#$59,#$5A,#$7B,#$7C,#$7D,#$7E,#$7F,<br>&nbsp; &nbsp; &nbsp;#$80,#$81,#$82,#$81,#$84,#$85,#$86,#$87,#$88,#$89,#$8A,#$8B,#$8C,#$8D,#$8E,#$8F,<br>&nbsp; &nbsp; &nbsp;#$80,#$91,#$92,#$93,#$94,#$95,#$96,#$97,#$98,#$99,#$8A,#$9B,#$8C,#$8D,#$8E,#$8F,<br>&nbsp; &nbsp; &nbsp;#$A0,#$A1,#$A1,#$A3,#$A4,#$A5,#$A6,#$A7,#$A8,#$A9,#$AA,#$AB,#$AC,#$AD,#$AE,#$AF,<br>&nbsp; &nbsp; &nbsp;#$B0,#$B1,#$B2,#$B2,#$A5,#$B5,#$B6,#$B7,#$A8,#$B9,#$AA,#$BB,#$A3,#$BD,#$BD,#$AF,<br>&nbsp; &nbsp; &nbsp;#$C0,#$C1,#$C2,#$C3,#$C4,#$C5,#$C6,#$C7,#$C8,#$C9,#$CA,#$CB,#$CC,#$CD,#$CE,#$CF,<br>&nbsp; &nbsp; &nbsp;#$D0,#$D1,#$D2,#$D3,#$D4,#$D5,#$D6,#$D7,#$D8,#$D9,#$DA,#$DB,#$DC,#$DD,#$DE,#$DF,<br>&nbsp; &nbsp; &nbsp;#$C0,#$C1,#$C2,#$C3,#$C4,#$C5,#$C6,#$C7,#$C8,#$C9,#$CA,#$CB,#$CC,#$CD,#$CE,#$CF,<br>&nbsp; &nbsp; &nbsp;#$D0,#$D1,#$D2,#$D3,#$D4,#$D5,#$D6,#$D7,#$D8,#$D9,#$DA,#$DB,#$DC,#$DD,#$DE,#$DF);<br><br>implementation<br><br>{$R *.DFM}<br><br>{<br>&nbsp; 在SourceString中搜索FindString,StartPos是起始搜索位置。如果没搜索到,返回0。区分大小写。<br>&nbsp; 你可以将返回值赋给StartPos,查找下一个匹配的字符串。<br>}<br>function Q_PosStr(const FindString, SourceString: string; StartPos: Integer): Integer;<br>asm<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;ESI<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; TEST &nbsp; &nbsp;EAX,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt<br>&nbsp; &nbsp; &nbsp; &nbsp; TEST &nbsp; &nbsp;EDX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt0<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; ESI,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EDI,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EAX,[EAX-4]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EDX,[EDX-4]<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; EDX,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; EDX,ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JNG &nbsp; &nbsp; @@qt0<br>&nbsp; &nbsp; &nbsp; &nbsp; XCHG &nbsp; &nbsp;EAX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; ADD &nbsp; &nbsp; EDI,ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; ECX,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; JMP &nbsp; &nbsp; @@nx<br>@@fr: &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt0<br>@@nx: &nbsp; MOV &nbsp; &nbsp; EBX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [ESI]<br>@@lp1: &nbsp;CMP &nbsp; &nbsp; AL,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt0<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt0<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt0<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@lp1<br>@@qt0: &nbsp;XOR &nbsp; &nbsp; EAX,EAX<br>@@qt: &nbsp; POP &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ESI<br>&nbsp; &nbsp; &nbsp; &nbsp; RET<br>@@uu: &nbsp; TEST &nbsp; &nbsp;EDX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@fd<br>@@lp2: &nbsp;MOV &nbsp; &nbsp; AL,BYTE PTR [ESI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@fr<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@fd<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [ESI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@fr<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@fd<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [ESI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@fr<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@fd<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [ESI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EDI+EBX]<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@fr<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@lp2<br>@@fd: &nbsp; LEA &nbsp; &nbsp; EAX,[EDI+1]<br>&nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; EAX,[ESP]<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ESI<br>end;<br><br>{ 功能同上,不区分大小写。使用此函数时,要在Interface部分加入ToUpperChars常量数组 }<br>function Q_PosText(const FindString, SourceString: string; StartPos: Integer): Integer;<br>asm<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;ESI<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; TEST &nbsp; &nbsp;EAX,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt<br>&nbsp; &nbsp; &nbsp; &nbsp; TEST &nbsp; &nbsp;EDX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qt0<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; ESI,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EDI,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EAX,[EAX-4]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EDX,[EDX-4]<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; EDX,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSH &nbsp; &nbsp;EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; EDX,ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JNG &nbsp; &nbsp; @@qtx<br>&nbsp; &nbsp; &nbsp; &nbsp; ADD &nbsp; &nbsp; EDI,ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; ECX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EDX,EAX<br>&nbsp; &nbsp; &nbsp; &nbsp; MOVZX &nbsp; EBX,BYTE PTR [ESI]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>@@lp1: &nbsp;MOVZX &nbsp; EBX,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>@@fr: &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qtx<br>&nbsp; &nbsp; &nbsp; &nbsp; MOVZX &nbsp; EBX,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qtx<br>&nbsp; &nbsp; &nbsp; &nbsp; MOVZX &nbsp; EBX,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@qtx<br>&nbsp; &nbsp; &nbsp; &nbsp; MOVZX &nbsp; EBX,BYTE PTR [EDI]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@uu<br>&nbsp; &nbsp; &nbsp; &nbsp; INC &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; DEC &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@lp1<br>@@qtx: &nbsp;ADD &nbsp; &nbsp; ESP,$08<br>@@qt0: &nbsp;XOR &nbsp; &nbsp; EAX,EAX<br>@@qt: &nbsp; POP &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ESI<br>&nbsp; &nbsp; &nbsp; &nbsp; RET<br>@@ms: &nbsp; MOVZX &nbsp; EBX,BYTE PTR [ESI]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; EDX,[ESP]<br>&nbsp; &nbsp; &nbsp; &nbsp; JMP &nbsp; &nbsp; @@fr<br>@@uu: &nbsp; TEST &nbsp; &nbsp;EDX,EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@fd<br>@@lp2: &nbsp;MOV &nbsp; &nbsp; BL,BYTE PTR [ESI+EDX]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AH,BYTE PTR [EDI+EDX]<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; BL,AH<br>&nbsp; &nbsp; &nbsp; &nbsp; JE &nbsp; &nbsp; &nbsp;@@eq<br>&nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; MOVZX &nbsp; EBX,AH<br>&nbsp; &nbsp; &nbsp; &nbsp; CMP &nbsp; &nbsp; AL,BYTE PTR [EBX+ToUpperChars]<br>&nbsp; &nbsp; &nbsp; &nbsp; JNE &nbsp; &nbsp; @@ms<br>@@eq: &nbsp; DEC &nbsp; &nbsp; EDX<br>&nbsp; &nbsp; &nbsp; &nbsp; JNZ &nbsp; &nbsp; @@lp2<br>@@fd: &nbsp; LEA &nbsp; &nbsp; EAX,[EDI+1]<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; EAX,[ESP]<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ECX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EBX<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; EDI<br>&nbsp; &nbsp; &nbsp; &nbsp; POP &nbsp; &nbsp; ESI<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; iPos: Integer;<br>begin<br>&nbsp; iPos := Q_PosStr('x', 'wo shi xiaobenben', 1);<br>&nbsp; if iPos = 0 then<br>&nbsp; &nbsp; Caption := '没找到!'<br>&nbsp; else<br>&nbsp; &nbsp; Caption := '找到了,第一次出现的位置是:' + IntToStr(iPos);<br>end;<br><br>end.<br>
 
字符串中最后一个字符a的位置,怎么表示
 
&gt;&gt;字符串中最后一个字符a的位置,怎么表示<br>什么意思?你是说从倒数第一个匹配的字符串查起吗?
 
for i = length(s) downto 1 do<br>&nbsp; if s=a then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;Result=I;<br>&nbsp; &nbsp; &nbsp;break;<br>&nbsp; end;
 
假如这个字符串有n个a,我得到最后一个a的位置。<br>我得到a的位置的目的是得到最后一个a后面的字符。要是有直接的函数也行。
 
????<br>那不是很简单吗?稍微变通一下就可以了,用我给你的函数查找到整个字符串的第一个字符的<br>位置,你自己再加上这个字符串的长度(Length(s)),a后面的那个字符的位置了吗?
 
是不是想得到字符窗口的反序,然后就可是得到第一个a的位置。<br>然后得到整个字符的长度,然后相减就得到正序的最后一个a的位置。
 
你最好举个实际的例子
 
我的目的得到路径下的文件名,比如说D:/PROGRAM FILES/Borland/Delphi7.0/<br>&nbsp;我要得到‘Delphi‘这个字符。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;我这样 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if childwindowtext[Length(childwindowtext)] = '/' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Filepath := Copy(childwindowtext, 1, Length(childwindowtext) - 1) ;//if路径最后一个是'/'则去'/'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n:=AnsiPos(ReverseString(Filepath),'/') &nbsp;;Filepath反序的第一个'/'的位置,及正序最后一个'/'的位置。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if n&lt;&gt; 0 &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Filename:=copy(Filepath, (Length(Filepath)-n,'/'+2),(Length(Filepath)-[Length(Filepath)-n,'/'+2]);//copy最后一个/后面到末尾的字符。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp;我得到的文件有版本号,如何去掉他。现在我得到是Delphi7.0,这个版本号如何去掉?
 
结束话题了
 
后退
顶部