Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/MojuUtils.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download) (as text)
Tue Nov 25 17:50:53 2003 UTC (20 years, 4 months ago) by h677
Branch: MAIN
File MIME type: text/x-pascal
ちょっとだけ早い文字列置換関数(TStringList相手だと結構早い)

1 h677 1.1 unit MojuUtils;
2     //**************************
3     // 篁?????????絖???臀???∽? CustomStringReplace????????
4     //**************************
5    
6     interface
7    
8     uses
9     Classes, SysUtils;
10    
11     function CustomStringReplace(S , OldPattern: String;const NewPattern: string): String; overload;
12     function CustomStringReplace(S , OldPattern: String;const NewPattern: string; IgnoreCase : Boolean): String; overload;
13     procedure CustomStringReplace(var S : TStringList; OldPattern: String;const NewPattern: string);overload;
14     procedure CustomStringReplace(var S : TStringList; OldPattern: String;const NewPattern: string; IgnoreCase : Boolean);overload;
15    
16    
17     implementation
18    
19     function CustomStringReplace(
20     S ,OldPattern: String;
21     const NewPattern: string
22     ): String;
23     var
24     position : Integer;
25     lenOld : Integer;//OldPattern???激??
26     begin
27    
28     position := 0;
29     lenOld := Length(OldPattern);
30     Result := '';
31     position := AnsiPos( OldPattern, S);
32     while position <> 0 do begin
33     Result := Result + Copy(S,1,position -1 ) + NewPattern;
34     Delete(S,1, position + lenOld - 1);
35     position := AnsiPos( OldPattern, S);
36     end;
37     if Length( S ) > 0 then begin
38     Result := Result + S;
39     end;
40    
41    
42     end;
43     function CustomStringReplace(
44     S , OldPattern: String;
45     const NewPattern: string;
46     IgnoreCase : Boolean
47     ): String;
48     var
49     position : Integer;
50     lenOld : Integer;//OldPattern???激??
51     buffer : String;
52     begin
53     position := 0;
54     lenOld := Length(OldPattern);
55     Result := '';
56     if not IgnoreCase then begin
57     Result := CustomStringReplace( S, OldPattern, NewPattern );
58     end else begin
59     buffer := AnsiLowerCase(S);
60     OldPattern := AnsiLowerCase(OldPattern);
61     position := AnsiPos( OldPattern, buffer);
62     while position <> 0 do begin
63     Result := Result + Copy(S,1,position -1 ) + NewPattern;
64     Delete(S,1, position + lenOld - 1);
65     Delete(buffer,1, position + lenOld - 1);
66     position := AnsiPos( OldPattern, buffer);
67     end;
68     if Length( S ) > 0 then begin
69     Result := Result + S;
70     end;
71     end;
72     end;
73     procedure CustomStringReplace(
74     var S : TStringList;
75     OldPattern: String;
76     const NewPattern: string;
77     IgnoreCase : Boolean
78     );
79     var
80     i : Integer;
81     begin
82     if not IgnoreCase then begin
83     for i := 0 to S.Count - 1 do begin
84     S.Strings[i] := CustomStringReplace( S.Strings[i], OldPattern, NewPattern );
85     end;
86     end else begin
87     for i := 0 to S.Count - 1 do begin
88     S.Strings[i] := CustomStringReplace( S.Strings[i], OldPattern, NewPattern,IgnoreCase );
89     end;
90     end;
91     end;
92     procedure CustomStringReplace(
93     var S : TStringList;
94     OldPattern: String;
95     const NewPattern: string
96     );
97     var
98     i : Integer;
99     begin
100     for i := 0 to S.Count - 1 do begin
101     S.Strings[i] := CustomStringReplace( S.Strings[i], OldPattern, NewPattern );
102     end;
103     end;
104     end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26