stringreplace只能对string操作,当字符串长度大于255时,有没有什么函数?(200分)

  • 主题发起人 主题发起人 kuikui
  • 开始时间 开始时间
K

kuikui

Unregistered / Unconfirmed
GUEST, unregistred user!
stringreplace只能对string操作,当字符串长度大于255时,有没有什么函数?
 
一样可以啊:)
不过效率稍微低一点,如果需要非常高的效率,可以自己写一个,如果不需要,
就用这个就可以了:)
 
????有这样的限制吗????
 
呵呵,没有这样的限制,如果想效率高,自己写一个,其实就是查找字符的速度,
可以用一些特殊的匹配算法提高效率
 
呵呵,我总算是出手比你们快了一次:)
 
没有限制的吧
 
等于没说!
 
使用外挂的vbscript.dll中的正则表达式接口
使用正则表达式来进行替换和修改,速度非常快.
http://www.playicq.com 中有介绍如何使DELPHI支持正则表达式的内容。去看看吧
至于正则表达式怎么用,网上N多了。。。。
 
喂,是你自己没说清楚吧?何况什么叫“没说”?你倒是说清楚啊?为什么?
你不说我们怎么知道呢?[:D]
 
//只能对string操作,当字符串长度大于255时
先提醒你,只要字符串的长度小于 4G(别说 255 了),那它就还是一个字符串(string)
 
Delphi自带的StringReplace确实效率低,下面我给你两个函数,是世界级程序高手用汇编
语言写的,速度绝对快,你可以和StringReplace比一下,
function Q_ReplaceStr (const SourceString, FindString, ReplaceString: string): string;
替换所有符合要求的字符串,区分大小写。
function Q_ReplaceText (const SourceString, FindString, ReplaceString: string): string;
功能同上。不区分大小写
下面是程序例子,你直接将两段//+-+-+-+-+-+-+-+-中间的代码拷贝到你的程序中,再直接
调用这两个函数就可以了。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

const
ToUpperChars: array[0..255] of Char =
(#$00,#$01,#$02,#$03,#$04,#$05,#$06,#$07,#$08,#$09,#$0A,#$0B,#$0C,#$0D,#$0E,#$0F,
#$10,#$11,#$12,#$13,#$14,#$15,#$16,#$17,#$18,#$19,#$1A,#$1B,#$1C,#$1D,#$1E,#$1F,
#$20,#$21,#$22,#$23,#$24,#$25,#$26,#$27,#$28,#$29,#$2A,#$2B,#$2C,#$2D,#$2E,#$2F,
#$30,#$31,#$32,#$33,#$34,#$35,#$36,#$37,#$38,#$39,#$3A,#$3B,#$3C,#$3D,#$3E,#$3F,
#$40,#$41,#$42,#$43,#$44,#$45,#$46,#$47,#$48,#$49,#$4A,#$4B,#$4C,#$4D,#$4E,#$4F,
#$50,#$51,#$52,#$53,#$54,#$55,#$56,#$57,#$58,#$59,#$5A,#$5B,#$5C,#$5D,#$5E,#$5F,
#$60,#$41,#$42,#$43,#$44,#$45,#$46,#$47,#$48,#$49,#$4A,#$4B,#$4C,#$4D,#$4E,#$4F,
#$50,#$51,#$52,#$53,#$54,#$55,#$56,#$57,#$58,#$59,#$5A,#$7B,#$7C,#$7D,#$7E,#$7F,
#$80,#$81,#$82,#$81,#$84,#$85,#$86,#$87,#$88,#$89,#$8A,#$8B,#$8C,#$8D,#$8E,#$8F,
#$80,#$91,#$92,#$93,#$94,#$95,#$96,#$97,#$98,#$99,#$8A,#$9B,#$8C,#$8D,#$8E,#$8F,
#$A0,#$A1,#$A1,#$A3,#$A4,#$A5,#$A6,#$A7,#$A8,#$A9,#$AA,#$AB,#$AC,#$AD,#$AE,#$AF,
#$B0,#$B1,#$B2,#$B2,#$A5,#$B5,#$B6,#$B7,#$A8,#$B9,#$AA,#$BB,#$A3,#$BD,#$BD,#$AF,
#$C0,#$C1,#$C2,#$C3,#$C4,#$C5,#$C6,#$C7,#$C8,#$C9,#$CA,#$CB,#$CC,#$CD,#$CE,#$CF,
#$D0,#$D1,#$D2,#$D3,#$D4,#$D5,#$D6,#$D7,#$D8,#$D9,#$DA,#$DB,#$DC,#$DD,#$DE,#$DF,
#$C0,#$C1,#$C2,#$C3,#$C4,#$C5,#$C6,#$C7,#$C8,#$C9,#$CA,#$CB,#$CC,#$CD,#$CE,#$CF,
#$D0,#$D1,#$D2,#$D3,#$D4,#$D5,#$D6,#$D7,#$D8,#$D9,#$DA,#$DB,#$DC,#$DD,#$DE,#$DF);

procedure Q_TinyCopy(Source, Dest: Pointer
L: Cardinal);
asm
JMP DWORD PTR @@tV[ECX*4]
@@tV: DD @@tu00, @@tu01, @@tu02, @@tu03
DD @@tu04, @@tu05, @@tu06, @@tu07
DD @@tu08, @@tu09, @@tu10, @@tu11
DD @@tu12, @@tu13, @@tu14, @@tu15
DD @@tu16, @@tu17, @@tu18, @@tu19
DD @@tu20, @@tu21, @@tu22, @@tu23
DD @@tu24, @@tu25, @@tu26, @@tu27
DD @@tu28, @@tu29, @@tu30, @@tu31
DD @@tu32
@@tu00: RET
@@tu01: MOV CL,BYTE PTR [EAX]
MOV BYTE PTR [EDX],CL
RET
@@tu02: MOV CX,WORD PTR [EAX]
MOV WORD PTR [EDX],CX
RET
@@tu03: MOV CX,WORD PTR [EAX]
MOV WORD PTR [EDX],CX
MOV CL,BYTE PTR [EAX+2]
MOV BYTE PTR [EDX+2],CL
RET
@@tu04: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
RET
@@tu05: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV CL,BYTE PTR [EAX+4]
MOV BYTE PTR [EDX+4],CL
RET
@@tu06: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV CX,WORD PTR [EAX+4]
MOV WORD PTR [EDX+4],CX
RET
@@tu07: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV CX,WORD PTR [EAX+4]
MOV WORD PTR [EDX+4],CX
MOV CL,BYTE PTR [EAX+6]
MOV BYTE PTR [EDX+6],CL
RET
@@tu08: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
RET
@@tu09: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV CL,BYTE PTR [EAX+8]
MOV BYTE PTR [EDX+8],CL
RET
@@tu10: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV CX,WORD PTR [EAX+8]
MOV WORD PTR [EDX+8],CX
RET
@@tu11: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV CX,WORD PTR [EAX+8]
MOV WORD PTR [EDX+8],CX
MOV CL,BYTE PTR [EAX+10]
MOV BYTE PTR [EDX+10],CL
RET
@@tu12: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
RET
@@tu13: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV CL,BYTE PTR [EAX+12]
MOV BYTE PTR [EDX+12],CL
RET
@@tu14: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV CX,WORD PTR [EAX+12]
MOV WORD PTR [EDX+12],CX
RET
@@tu15: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV CX,WORD PTR [EAX+12]
MOV WORD PTR [EDX+12],CX
MOV CL,BYTE PTR [EAX+14]
MOV BYTE PTR [EDX+14],CL
RET
@@tu16: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
RET
@@tu17: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV CL,BYTE PTR [EAX+16]
MOV BYTE PTR [EDX+16],CL
RET
@@tu18: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV CX,WORD PTR [EAX+16]
MOV WORD PTR [EDX+16],CX
RET
@@tu19: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV CX,WORD PTR [EAX+16]
MOV WORD PTR [EDX+16],CX
MOV CL,BYTE PTR [EAX+18]
MOV BYTE PTR [EDX+18],CL
RET
@@tu20: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
RET
@@tu21: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV CL,BYTE PTR [EAX+20]
MOV BYTE PTR [EDX+20],CL
RET
@@tu22: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV CX,WORD PTR [EAX+20]
MOV WORD PTR [EDX+20],CX
RET
@@tu23: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV CX,WORD PTR [EAX+20]
MOV WORD PTR [EDX+20],CX
MOV CL,BYTE PTR [EAX+22]
MOV BYTE PTR [EDX+22],CL
RET
@@tu24: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
RET
@@tu25: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV CL,BYTE PTR [EAX+24]
MOV BYTE PTR [EDX+24],CL
RET
@@tu26: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV CX,WORD PTR [EAX+24]
MOV WORD PTR [EDX+24],CX
RET
@@tu27: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV CX,WORD PTR [EAX+24]
MOV WORD PTR [EDX+24],CX
MOV CL,BYTE PTR [EAX+26]
MOV BYTE PTR [EDX+26],CL
RET
@@tu28: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV ECX,DWORD PTR [EAX+24]
MOV DWORD PTR [EDX+24],ECX
RET
@@tu29: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV ECX,DWORD PTR [EAX+24]
MOV DWORD PTR [EDX+24],ECX
MOV CL,BYTE PTR [EAX+28]
MOV BYTE PTR [EDX+28],CL
RET
@@tu30: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV ECX,DWORD PTR [EAX+24]
MOV DWORD PTR [EDX+24],ECX
MOV CX,WORD PTR [EAX+28]
MOV WORD PTR [EDX+28],CX
RET
@@tu31: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV ECX,DWORD PTR [EAX+24]
MOV DWORD PTR [EDX+24],ECX
MOV CX,WORD PTR [EAX+28]
MOV WORD PTR [EDX+28],CX
MOV CL,BYTE PTR [EAX+30]
MOV BYTE PTR [EDX+30],CL
RET
@@tu32: MOV ECX,DWORD PTR [EAX]
MOV DWORD PTR [EDX],ECX
MOV ECX,DWORD PTR [EAX+4]
MOV DWORD PTR [EDX+4],ECX
MOV ECX,DWORD PTR [EAX+8]
MOV DWORD PTR [EDX+8],ECX
MOV ECX,DWORD PTR [EAX+12]
MOV DWORD PTR [EDX+12],ECX
MOV ECX,DWORD PTR [EAX+16]
MOV DWORD PTR [EDX+16],ECX
MOV ECX,DWORD PTR [EAX+20]
MOV DWORD PTR [EDX+20],ECX
MOV ECX,DWORD PTR [EAX+24]
MOV DWORD PTR [EDX+24],ECX
MOV ECX,DWORD PTR [EAX+28]
MOV DWORD PTR [EDX+28],ECX
end;

procedure IntCopy16;
asm
MOV EAX,[ESI]
MOV [EDI],EAX
MOV EAX,[ESI+4]
MOV [EDI+4],EAX
MOV EAX,[ESI+8]
MOV [EDI+8],EAX
MOV EAX,[ESI+12]
MOV [EDI+12],EAX
MOV EAX,[ESI+16]
MOV [EDI+16],EAX
MOV EAX,[ESI+20]
MOV [EDI+20],EAX
MOV EAX,[ESI+24]
MOV [EDI+24],EAX
MOV EAX,[ESI+28]
MOV [EDI+28],EAX
MOV EAX,[ESI+32]
MOV [EDI+32],EAX
MOV EAX,[ESI+36]
MOV [EDI+36],EAX
MOV EAX,[ESI+40]
MOV [EDI+40],EAX
MOV EAX,[ESI+44]
MOV [EDI+44],EAX
MOV EAX,[ESI+48]
MOV [EDI+48],EAX
MOV EAX,[ESI+52]
MOV [EDI+52],EAX
MOV EAX,[ESI+56]
MOV [EDI+56],EAX
MOV EAX,[ESI+60]
MOV [EDI+60],EAX
end;

function Q_PosStr(const FindString, SourceString: string
StartPos: Integer): Integer;
asm
PUSH ESI
PUSH EDI
PUSH EBX
PUSH EDX
TEST EAX,EAX
JE @@qt
TEST EDX,EDX
JE @@qt0
MOV ESI,EAX
MOV EDI,EDX
MOV EAX,[EAX-4]
MOV EDX,[EDX-4]
DEC EAX
SUB EDX,EAX
DEC ECX
SUB EDX,ECX
JNG @@qt0
XCHG EAX,EDX
ADD EDI,ECX
MOV ECX,EAX
JMP @@nx
@@fr: INC EDI
DEC ECX
JE @@qt0
@@nx: MOV EBX,EDX
MOV AL,BYTE PTR [ESI]
@@lp1: CMP AL,BYTE PTR [EDI]
JE @@uu
INC EDI
DEC ECX
JE @@qt0
CMP AL,BYTE PTR [EDI]
JE @@uu
INC EDI
DEC ECX
JE @@qt0
CMP AL,BYTE PTR [EDI]
JE @@uu
INC EDI
DEC ECX
JE @@qt0
CMP AL,BYTE PTR [EDI]
JE @@uu
INC EDI
DEC ECX
JNE @@lp1
@@qt0: XOR EAX,EAX
@@qt: POP ECX
POP EBX
POP EDI
POP ESI
RET
@@uu: TEST EDX,EDX
JE @@fd
@@lp2: MOV AL,BYTE PTR [ESI+EBX]
CMP AL,BYTE PTR [EDI+EBX]
JNE @@fr
DEC EBX
JE @@fd
MOV AL,BYTE PTR [ESI+EBX]
CMP AL,BYTE PTR [EDI+EBX]
JNE @@fr
DEC EBX
JE @@fd
MOV AL,BYTE PTR [ESI+EBX]
CMP AL,BYTE PTR [EDI+EBX]
JNE @@fr
DEC EBX
JE @@fd
MOV AL,BYTE PTR [ESI+EBX]
CMP AL,BYTE PTR [EDI+EBX]
JNE @@fr
DEC EBX
JNE @@lp2
@@fd: LEA EAX,[EDI+1]
SUB EAX,[ESP]
POP ECX
POP EBX
POP EDI
POP ESI
end;

procedure Q_CopyMem(Source, Dest: Pointer
L: Cardinal);
asm
PUSH EDI
PUSH ESI
MOV EDI,EDX
MOV EDX,ECX
MOV ESI,EAX
TEST EDI,3
JNE @@cl
SHR ECX,2
AND EDX,3
CMP ECX,16
JBE @@cw0
@@lp0: CALL IntCopy16
ADD ESI,64
SUB ECX,16
ADD EDI,64
CMP ECX,16
JA @@lp0
@@cw0: JMP DWORD PTR @@wV[ECX*4]
@@cl: MOV EAX,EDI
MOV EDX,3
SUB ECX,4
JB @@bc
AND EAX,3
ADD ECX,EAX
JMP DWORD PTR @@lV[EAX*4-4]
@@bc: JMP DWORD PTR @@tV[ECX*4+16]
@@lV: DD @@l1, @@l2, @@l3
@@l1: AND EDX,ECX
MOV AL,[ESI]
MOV [EDI],AL
MOV AL,[ESI+1]
MOV [EDI+1],AL
MOV AL,[ESI+2]
SHR ECX,2
MOV [EDI+2],AL
ADD ESI,3
ADD EDI,3
CMP ECX,16
JBE @@cw1
@@lp1: CALL IntCopy16
ADD ESI,64
SUB ECX,16
ADD EDI,64
CMP ECX,16
JA @@lp1
@@cw1: JMP DWORD PTR @@wV[ECX*4]
@@l2: AND EDX,ECX
MOV AL,[ESI]
MOV [EDI],AL
MOV AL,[ESI+1]
SHR ECX,2
MOV [EDI+1],AL
ADD ESI,2
ADD EDI,2
CMP ECX,16
JBE @@cw2
@@lp2: CALL IntCopy16
ADD ESI,64
SUB ECX,16
ADD EDI,64
CMP ECX,16
JA @@lp2
@@cw2: JMP DWORD PTR @@wV[ECX*4]
@@l3: AND EDX,ECX
MOV AL,[ESI]
MOV [EDI],AL
INC ESI
SHR ECX,2
INC EDI
CMP ECX,16
JBE @@cw3
@@lp3: CALL IntCopy16
ADD ESI,64
SUB ECX,16
ADD EDI,64
CMP ECX,16
JA @@lp3
@@cw3: JMP DWORD PTR @@wV[ECX*4]
@@wV: DD @@w0, @@w1, @@w2, @@w3
DD @@w4, @@w5, @@w6, @@w7
DD @@w8, @@w9, @@w10, @@w11
DD @@w12, @@w13, @@w14, @@w15
DD @@w16
@@w16: MOV EAX,[ESI+ECX*4-64]
MOV [EDI+ECX*4-64],EAX
@@w15: MOV EAX,[ESI+ECX*4-60]
MOV [EDI+ECX*4-60],EAX
@@w14: MOV EAX,[ESI+ECX*4-56]
MOV [EDI+ECX*4-56],EAX
@@w13: MOV EAX,[ESI+ECX*4-52]
MOV [EDI+ECX*4-52],EAX
@@w12: MOV EAX,[ESI+ECX*4-48]
MOV [EDI+ECX*4-48],EAX
@@w11: MOV EAX,[ESI+ECX*4-44]
MOV [EDI+ECX*4-44],EAX
@@w10: MOV EAX,[ESI+ECX*4-40]
MOV [EDI+ECX*4-40],EAX
@@w9: MOV EAX,[ESI+ECX*4-36]
MOV [EDI+ECX*4-36],EAX
@@w8: MOV EAX,[ESI+ECX*4-32]
MOV [EDI+ECX*4-32],EAX
@@w7: MOV EAX,[ESI+ECX*4-28]
MOV [EDI+ECX*4-28],EAX
@@w6: MOV EAX,[ESI+ECX*4-24]
MOV [EDI+ECX*4-24],EAX
@@w5: MOV EAX,[ESI+ECX*4-20]
MOV [EDI+ECX*4-20],EAX
@@w4: MOV EAX,[ESI+ECX*4-16]
MOV [EDI+ECX*4-16],EAX
@@w3: MOV EAX,[ESI+ECX*4-12]
MOV [EDI+ECX*4-12],EAX
@@w2: MOV EAX,[ESI+ECX*4-8]
MOV [EDI+ECX*4-8],EAX
@@w1: MOV EAX,[ESI+ECX*4-4]
MOV [EDI+ECX*4-4],EAX
SHL ECX,2
ADD ESI,ECX
ADD EDI,ECX
@@w0: JMP DWORD PTR @@tV[EDX*4]
@@tV: DD @@t0, @@t1, @@t2, @@t3
@@t3: MOV AL,[ESI+2]
MOV [EDI+2],AL
@@t2: MOV AL,[ESI+1]
MOV [EDI+1],AL
@@t1: MOV AL,[ESI]
MOV [EDI],AL
@@t0: POP ESI
POP EDI
end;

function Q_ReplaceStr(const SourceString, FindString, ReplaceString: string): string;
var
P,PS: PChar;
L,L1,L2,Cnt: Integer;
I,J,K,M: Integer;
begin
L1 := Length(FindString);
Cnt := 0;
I := Q_PosStr(FindString,SourceString,1);
while I <> 0 do
begin
Inc(I,L1);
asm
PUSH I
end;
Inc(Cnt);
I := Q_PosStr(FindString,SourceString,I);
end;
if Cnt <> 0 then
begin
L := Length(SourceString);
L2 := Length(ReplaceString);
J := L+1;
Inc(L,(L2-L1)*Cnt);
if L <> 0 then
begin
SetString(Result,nil,L);
P := Pointer(Result);
Inc(P, L);
PS := Pointer(LongWord(SourceString)-1);
if L2 <= 32 then
for I := 0 to Cnt-1 do
begin
asm
POP K
end;
M := J-K;
if M > 0 then
begin
Dec(P,M);
Q_CopyMem(@PS[K],P,M);
end;
Dec(P,L2);
Q_TinyCopy(Pointer(ReplaceString),P,L2);
J := K-L1;
end
else
for I := 0 to Cnt-1 do
begin
asm
POP K
end;
M := J-K;
if M > 0 then
begin
Dec(P,M);
Q_CopyMem(@PS[K],P,M);
end;
Dec(P,L2);
Q_CopyMem(Pointer(ReplaceString),P,L2);
J := K-L1;
end;
Dec(J);
if J > 0 then
Q_CopyMem(Pointer(SourceString),Pointer(Result),J);
end else
Result := '';
end else
Result := SourceString;
end;

function Q_PosText(const FindString, SourceString: string
StartPos: Integer): Integer;
asm
PUSH ESI
PUSH EDI
PUSH EBX
TEST EAX,EAX
JE @@qt
TEST EDX,EDX
JE @@qt0
MOV ESI,EAX
MOV EDI,EDX
PUSH EDX
MOV EAX,[EAX-4]
MOV EDX,[EDX-4]
DEC EAX
SUB EDX,EAX
DEC ECX
PUSH EAX
SUB EDX,ECX
JNG @@qtx
ADD EDI,ECX
MOV ECX,EDX
MOV EDX,EAX
MOVZX EBX,BYTE PTR [ESI]
MOV AL,BYTE PTR [EBX+ToUpperChars]
@@lp1: MOVZX EBX,BYTE PTR [EDI]
CMP AL,BYTE PTR [EBX+ToUpperChars]
JE @@uu
@@fr: INC EDI
DEC ECX
JE @@qtx
MOVZX EBX,BYTE PTR [EDI]
CMP AL,BYTE PTR [EBX+ToUpperChars]
JE @@uu
INC EDI
DEC ECX
JE @@qtx
MOVZX EBX,BYTE PTR [EDI]
CMP AL,BYTE PTR [EBX+ToUpperChars]
JE @@uu
INC EDI
DEC ECX
JE @@qtx
MOVZX EBX,BYTE PTR [EDI]
CMP AL,BYTE PTR [EBX+ToUpperChars]
JE @@uu
INC EDI
DEC ECX
JNE @@lp1
@@qtx: ADD ESP,$08
@@qt0: XOR EAX,EAX
@@qt: POP EBX
POP EDI
POP ESI
RET
@@ms: MOVZX EBX,BYTE PTR [ESI]
MOV AL,BYTE PTR [EBX+ToUpperChars]
MOV EDX,[ESP]
JMP @@fr
@@uu: TEST EDX,EDX
JE @@fd
@@lp2: MOV BL,BYTE PTR [ESI+EDX]
MOV AH,BYTE PTR [EDI+EDX]
CMP BL,AH
JE @@eq
MOV AL,BYTE PTR [EBX+ToUpperChars]
MOVZX EBX,AH
CMP AL,BYTE PTR [EBX+ToUpperChars]
JNE @@ms
@@eq: DEC EDX
JNZ @@lp2
@@fd: LEA EAX,[EDI+1]
POP ECX
SUB EAX,[ESP]
POP ECX
POP EBX
POP EDI
POP ESI
end;

function Q_ReplaceText(const SourceString, FindString, ReplaceString: string): string;
var
P,PS: PChar;
L,L1,L2,Cnt: Integer;
I,J,K,M: Integer;
begin
L1 := Length(FindString);
Cnt := 0;
I := Q_PosText(FindString,SourceString,1);
while I <> 0 do
begin
Inc(I,L1);
asm
PUSH I
end;
Inc(Cnt);
I := Q_PosText(FindString,SourceString,I);
end;
if Cnt <> 0 then
begin
L := Length(SourceString);
L2 := Length(ReplaceString);
J := L+1;
Inc(L,(L2-L1)*Cnt);
if L <> 0 then
begin
SetString(Result,nil,L);
P := Pointer(Result);
Inc(P, L);
PS := Pointer(LongWord(SourceString)-1);
if L2 <= 32 then
for I := 0 to Cnt-1 do
begin
asm
POP K
end;
M := J-K;
if M > 0 then
begin
Dec(P,M);
Q_CopyMem(@PS[K],P,M);
end;
Dec(P,L2);
Q_TinyCopy(Pointer(ReplaceString),P,L2);
J := K-L1;
end
else
for I := 0 to Cnt-1 do
begin
asm
POP K
end;
M := J-K;
if M > 0 then
begin
Dec(P,M);
Q_CopyMem(@PS[K],P,M);
end;
Dec(P,L2);
Q_CopyMem(Pointer(ReplaceString),P,L2);
J := K-L1;
end;
Dec(J);
if J > 0 then
Q_CopyMem(Pointer(SourceString),Pointer(Result),J);
end else
Result := '';
end else
Result := SourceString;
end;

//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := Q_ReplaceStr('wo shi xiaobenben', 'ben', 'ling');
Caption := Q_ReplaceText('wo shi xiaobenBEN', 'ben', 'Ling');
end;

end.
 
delphi的String类型不是shortstring,所以没有255的限制,它是AnisString类型,理论上是无限制的!
 
收藏了,汇编看不懂
 
呵呵,这是典型的空间换速度:)
楼主那里去了?[:(]
 
汇编,没试,收藏.其它有启发,谢拉!
 
那段汇编代码我收藏过,确实很快
 
var
s:sting;
begin
setlength(s,500);
end;
 
tp里的string才有255限制。
delphi里不是,限制是High(Cardinal)
 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
回复
0
查看
866
不得闲
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
915
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部