Advertisement

03.05.2008 at 09:39PM PST, ID: 23218559
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Need a very fast case insensitive way of finding the last occurence of a WIDESTRING in another

Tags: delphi
I need to find the last occurence of a widestring within another widestring. I need the options of doing this in a case sensitive or case insensitive manner. I have looked at the FastStrings.pas unit but as far as I can tell it appears to be only for ordinary ANSI strings. Does anyone know of any libraries/code samples that will do the trick. The code needs to be fast and not restricted to specific cpu instructions sets. No generic answers like 'start looking from the back of the string' please :-)
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: dhowes_UK
Solution Provided By: dinilud
Participating Experts: 2
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
03.05.2008 at 10:41PM PST, ID: 21057905

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.05.2008 at 10:45PM PST, ID: 21057913

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.06.2008 at 12:31AM PST, ID: 21058337

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.06.2008 at 12:44AM PST, ID: 21058381

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.06.2008 at 12:52AM PST, ID: 21058425

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.06.2008 at 01:06AM PST, ID: 21058483

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.06.2008 at 06:55AM PST, ID: 21060675

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.05.2008 at 10:45PM PST, ID: 21057913

Rank: Guru

try StrPosW from above link
 
03.06.2008 at 12:31AM PST, ID: 21058337

Rank: Wizard

dinilud means StrScanW from above link :)
 
03.06.2008 at 12:44AM PST, ID: 21058381
Unfortunately none of the functions mentioned above will do. It is a SUBSTRING that I am looking for inside another widestring not an individual char. And i need the LAST SUBSTRING inside that widestring and I must be able to have the option of either a case sensitive or case insensitive match.
 
03.06.2008 at 12:52AM PST, ID: 21058425

Rank: Wizard

a wild idea, I don't know how long your data is:

how about you reverse your string and then use StrPosW to search for the reverse of your original data?
 
03.06.2008 at 01:06AM PST, ID: 21058483
The string can be quite long as in a MB or more. Reversing it isn't an option for performance reasons. And StePosW wouldn't let me do the search in a case insensitive way. I appreciate there are some obvious generic solutions to this such as converting both the search string and the source string to upper case before starting, but again performance would be an issue. The ideal solution if it exists would probably be some assembler the takes the back of the string as argument and works backwards to the first match it finds (being the last match in the string) but does so in a case insensitive way.
 
03.06.2008 at 06:55AM PST, ID: 21060675

Rank: Guru

try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
unit1.dfm
==========
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 544
  Height = 420
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 72
    Top = 208
    Width = 47
    Height = 13
    Caption = 'Sub string'
  end
  object Button1: TButton
    Left = 312
    Top = 248
    Width = 177
    Height = 41
    Caption = 'Last Occurence'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 2
    Top = 1
    Width = 525
    Height = 188
    Lines.Strings = (
      'procedure TForm1.Button1Click(Sender: TObject);'
      ' var'
      '  A, B: WideString;'
      '  P: PWideChar;'
      ''
      'begin'
      '  A := Edit1.Text;'
      '  B := Memo1.Text;'
      '  P := WStrPos(PWideChar(B), PWideChar(A));'
      ''
      '  if P = nil then ShowMessage(''FAIL #1 - P is nil!'')'
      '  else showmessage(WideString(P));'
      'end;')
    ScrollBars = ssBoth
    TabOrder = 1
  end
  object Edit1: TEdit
    Left = 136
    Top = 200
    Width = 257
    Height = 21
    TabOrder = 2
    Text = 'showmessage'
  end
  object Button2: TButton
    Left = 48
    Top = 248
    Width = 201
    Height = 41
    Caption = 'First Occurence'
    TabOrder = 3
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 48
    Top = 312
    Width = 201
    Height = 41
    Caption = 'First Occurence(case insensitive)'
    TabOrder = 4
    OnClick = Button3Click
  end
  object Button4: TButton
    Left = 312
    Top = 312
    Width = 177
    Height = 41
    Caption = 'Last Occurence (case insensitive)'
    TabOrder = 5
    OnClick = Button4Click
  end
end
 
unit1.pas
==========
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    Label1: TLabel;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
function MyStrPosW(Str, SubStr: PWideChar): PWideChar;
asm
         PUSH EDI
         PUSH ESI
         PUSH EBX
         OR EAX, EAX
         JZ @@2
         OR EDX, EDX
         JZ @@2
         MOV EBX, EAX
         MOV EDI, EDX
         XOR AX, AX
         MOV ECX, 0FFFFFFFFH
         REPNE SCASW
         NOT ECX
         DEC ECX
         JZ @@2
         MOV ESI, ECX
         MOV EDI, EBX
         MOV ECX, 0FFFFFFFFH
         REPNE SCASW
         NOT ECX
         SUB ECX, ESI
         JBE @@2
         MOV EDI, EBX
         LEA EBX, [ESI - 1]
@@1:     MOV ESI, EDX
         LODSW
         REPNE SCASW
         JNE @@2
         MOV EAX, ECX
         PUSH EDI
         MOV ECX, EBX
         REPE CMPSW
         POP EDI
         MOV ECX, EAX
         JNE @@1
         LEA EAX, [EDI - 2]
         JMP @@3
 
@@2:     XOR EAX, EAX
@@3:     POP EBX
         POP ESI
         POP EDI
end;
 
 
function MyRStrPosW(Str, SubStr: PWideChar): PWideChar;
asm
        PUSH    EDI
        PUSH    ESI
        PUSH    EBX
        OR      EAX,EAX
        JE      @@2
        OR      EDX,EDX
        JE      @@2
        MOV     EBX,EAX
        MOV     EDI,EDX
        XOR     AX,AX
        MOV     ECX,0FFFFFFFFH
        REPNE   SCASW
        NOT     ECX
        DEC     ECX
        JZ      @@2
        MOV     ESI,ECX
        MOV     EDI,EBX
        MOV     ECX,0FFFFFFFFH
        REPNE   SCASW
        NOT     ECX
        SUB     ECX,ESI
        JBE     @@2
        LEA     EBX,[ESI-1]
@@1:    MOV     ESI,EDX
        MOV AX,[EDX]
        PUSH EBX
        LEA EDI,[EDI-4]
@@4:    MOV BX,[EDI]
        CMP AX,BX
        LEA EDI,[EDI-2]
        LOOPNE  @@4
        POP EBX
        JNE     @@2
        LEA EDI,[EDI+2]
        MOV     EAX,ECX
        PUSH    EDI
        MOV     ECX,EBX
        REPE    CMPSW
        POP     EDI
        MOV     ECX,EAX
        JNE     @@1
        LEA     EAX,[EDI]
        JMP     @@3
@@2:    XOR     EAX,EAX
@@3:    POP     EBX
        POP     ESI
        POP     EDI
end;
 
procedure TForm1.Button3Click(Sender: TObject);
 var
  A, B: WideString;
  P: PWideChar;
  x:Cardinal;
begin
  x:=GetTickCount;
  A := UpperCase(Edit1.Text);
  B := UpperCase(Memo1.Text);
  P := MyStrPosW(PWideChar(B), PWideChar(A));
  ShowMessage(IntToStr(GetTickCount-x));
  if P = nil then ShowMessage('FAIL #1 - P is nil!')
  else showmessage(WideString(P));
 
end;
 
 
 
procedure TForm1.Button1Click(Sender: TObject);
 var
  A, B: WideString;
  P: PWideChar;
  x:Cardinal;
begin
  x:=GetTickCount;
  A := Edit1.Text;
  B := Memo1.Text;
  P := MyRStrPosW(PWideChar(B), PWideChar(A));
  ShowMessage(IntToStr(GetTickCount-x));
  if P = nil then ShowMessage('FAIL #1 - P is nil!')
  else showmessage(WideString(P));
 
end;
 
procedure TForm1.Button2Click(Sender: TObject);
 var
  A, B: WideString;
  P: PWideChar;
  x:Cardinal;
begin
  x:=GetTickCount;
  A := Edit1.Text;
  B := Memo1.Text;
  P := MyStrPosW(PWideChar(B), PWideChar(A));
  ShowMessage(IntToStr(GetTickCount-x));
  if P = nil then ShowMessage('FAIL #1 - P is nil!')
  else showmessage(WideString(P));
 
end;
 
procedure TForm1.Button4Click(Sender: TObject);
 var
  A, B: WideString;
  P: PWideChar;
  x:Cardinal;
begin
  x:=GetTickCount;
  A := UpperCase(Edit1.Text);
  B := UpperCase(Memo1.Text);
  P := MyRStrPosW(PWideChar(B), PWideChar(A));
  ShowMessage(IntToStr(GetTickCount-x));
  if P = nil then ShowMessage('FAIL #1 - P is nil!')
  else showmessage(WideString(P));
end;
 
end.
Open in New Window
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628