Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi PosEx für Delphi 5? (https://www.delphipraxis.net/89187-posex-fuer-delphi-5-a.html)

xZise 27. Mär 2007 09:19


PosEx für Delphi 5?
 
Gibt es PosEx für Delphi 5?

SirThornberry 27. Mär 2007 09:20

Re: PosEx für Delphi 5?
 
unter delphi5 gibt es posex nicht. Aber du kannst dir doch ohne probleme selbst eine solche Funktion schreiben.

Andidreas 27. Mär 2007 09:37

Re: PosEx für Delphi 5?
 
das hab ich mal selber geschrieben, sollte posex fast gleichen

Delphi-Quellcode:
function TMain_Form.fnPos(sRow, sChar : String; iVonSt : Integer) : Integer;
   
var
i, iLen : Integer;
   
begin
   
  iLen := Length(sRow);
   
  For i := iVonSt To iLen Do
  Begin
    If sRow[i] = sChar Then
    Begin
      fnPos := i;
      Break;
    End;
  End;
   
end;

SirThornberry 27. Mär 2007 09:42

Re: PosEx für Delphi 5?
 
deine Funktion dürfte aber nicht funktionieren wenn man nicht nur nach einem zeischen sondern nach einem String sucht.

xZise 27. Mär 2007 09:44

Re: PosEx für Delphi 5?
 
Mein PosEx-Klon:
Delphi-Quellcode:
function PosEx(Substr, s : string; Offset : Integer = 0) : Integer;
begin
  Result := 0;
  Delete(s, 1, Offset);
  Result := Pos(Substr, s) + Offset;
end;

IngoD7 27. Mär 2007 10:00

Re: PosEx für Delphi 5?
 
Zitat:

Zitat von xZise
Mein PosEx-Klon:
Delphi-Quellcode:
function PosEx(Substr, s : string; Offset : Integer = 0) : Integer;
begin
  Result := 0;
  Delete(s, 1, Offset);
  Result := Pos(Substr, s) + Offset;
end;

Den Klon kannste vergessen, oder?
Der liefert ja immer ein Ergebnis, wenn Offset größer 0 ist. Auch wenn Substr überhaupt nicht vor kommt.

PosEx ist in Delphi folgendes - aus OH:
Zitat:

Delphi-Syntax:

function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;

Beschreibung:
PosEx gibt den Index von SubStr in S zurück, wobei die Suche bei Offset begonnen wird. Wenn Offset 1 ist (Vorgabe), entspricht PosEx Pos.

PosEx gibt 0 zurück, wenn SubStr nicht gefunden wird, Offset größer als die Länge von S ist oder Offset kleiner als 1 ist.

xZise 27. Mär 2007 10:07

Re: PosEx für Delphi 5?
 
Zitat:

Zitat von IngoD7
Den Klon kannste vergessen, oder?
Der liefert ja immer ein Ergebnis, wenn Offset größer 0 ist. Auch wenn Substr überhaupt nicht vor kommt.

Stimmt... Werde das also nochmal überprüfen, ob Pos = 0 ist ...

bitsetter 27. Mär 2007 10:15

Re: PosEx für Delphi 5?
 
Hi,

in der Code-Lib ist auch PosEx drin:
PosEx

CK_CK 27. Mär 2007 10:31

Re: PosEx für Delphi 5?
 
Der originale PosEx-Code ist folgender:
Delphi-Quellcode:
(* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The implementation of function PosEx is subject to the
 * Mozilla Public License Version 1.1 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at [url]http://www.mozilla.org/MPL/[/url]
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Fastcode
 *
 * The Initial Developer of the Original Code is Fastcode
 *
 * Portions created by the Initial Developer are Copyright (C) 2002-2004
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Aleksandr Sharahov
 *
 * ***** END LICENSE BLOCK ***** *)
function PosEx(const SubStr, S: string; Offset: Integer = 1): Integer;
asm
       test eax, eax
       jz   @Nil
       test edx, edx
       jz   @Nil
       dec  ecx
       jl   @Nil

       push esi
       push ebx

       mov  esi, [edx-4] //Length(Str)
       mov  ebx, [eax-4] //Length(Substr)
       sub  esi, ecx     //effective length of Str
       add  edx, ecx     //addr of the first char at starting position
       cmp  esi, ebx
       jl   @Past        //jump if EffectiveLength(Str)<Length(Substr)
       test ebx, ebx
       jle  @Past        //jump if Length(Substr)<=0

       add  esp, -12
       add  ebx, -1       //Length(Substr)-1
       add  esi, edx     //addr of the terminator
       add  edx, ebx     //addr of the last char at starting position
       mov  [esp+8], esi //save addr of the terminator
       add  eax, ebx     //addr of the last char of Substr
       sub  ecx, edx     //-@Str[Length(Substr)]
       neg  ebx          //-(Length(Substr)-1)
       mov  [esp+4], ecx //save -@Str[Length(Substr)]
       mov  [esp], ebx   //save -(Length(Substr)-1)
       movzx ecx, byte ptr [eax] //the last char of Substr

@Loop:
       cmp  cl, [edx]
       jz   @Test0
@AfterTest0:
       cmp  cl, [edx+1]
       jz   @TestT
@AfterTestT:
       add  edx, 4
       cmp  edx, [esp+8]
       jb  @Continue
@EndLoop:
       add  edx, -2
       cmp  edx, [esp+8]
       jb   @Loop
@Exit:
       add  esp, 12
@Past:
       pop  ebx
       pop  esi
@Nil:
       xor  eax, eax
       ret
@Continue:
       cmp  cl, [edx-2]
       jz   @Test2
       cmp  cl, [edx-1]
       jnz  @Loop
@Test1:
       add  edx, 1
@Test2:
       add  edx, -2
@Test0:
       add  edx, -1
@TestT:
       mov  esi, [esp]
       test esi, esi
       jz   @Found
@String:
       movzx ebx, word ptr [esi+eax]
       cmp  bx, word ptr [esi+edx+1]
       jnz  @AfterTestT
       cmp  esi, -2
       jge  @Found
       movzx ebx, word ptr [esi+eax+2]
       cmp  bx, word ptr [esi+edx+3]
       jnz  @AfterTestT
       add  esi, 4
       jl   @String
@Found:
       mov  eax, [esp+4]
       add  edx, 2

       cmp  edx, [esp+8]
       ja   @Exit

       add  esp, 12
       add  eax, edx
       pop  ebx
       pop  esi
end;
Vielleicht hilft's dir ja ;)

Chris

Andidreas 27. Mär 2007 11:58

Re: PosEx für Delphi 5?
 
Zitat:

Zitat von SirThornberry
deine Funktion dürfte aber nicht funktionieren wenn man nicht nur nach einem zeischen sondern nach einem String sucht.

joa des weiß ich das meine funktion nur funktioniert wenn man nach einem bestimmten zeichen sucht, aber ich bin davon ausgegangen das posex genau das macht :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:07 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz