AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

in strings suchen

Ein Thema von geisi · begonnen am 17. Okt 2005 · letzter Beitrag vom 18. Okt 2005
Antwort Antwort
geisi

Registriert seit: 19. Sep 2003
449 Beiträge
 
Delphi 6 Professional
 
#1

in strings suchen

  Alt 17. Okt 2005, 22:17
was gibt pos() zurück, wenn der substring nicht gefunden wird?
in der delphihilfe steht null(ist das nil, oder 0)
mfg geisi
  Mit Zitat antworten Zitat
Benutzerbild von sniper_w
sniper_w

Registriert seit: 11. Dez 2004
Ort: Wien, Österriech
893 Beiträge
 
Delphi 6 Enterprise
 
#2

Re: in strings suchen

  Alt 17. Okt 2005, 22:22
null ist in Englisch 0. Und Pos ist so deklariert:
function Pos(...):Integer;
Katura Haris
Es (ein gutes Wort) ist wie ein guter Baum, dessen Wurzel fest ist und dessen Zweige in den Himmel reichen.
  Mit Zitat antworten Zitat
geisi

Registriert seit: 19. Sep 2003
449 Beiträge
 
Delphi 6 Professional
 
#3

Re: in strings suchen

  Alt 17. Okt 2005, 22:28
Delphi-Quellcode:
...
begin
  text := 'hallo Test!';
  suche_nach := 'hallo';
  i := pos(suche_nach,text);
end;
müsste pos hier nicht auch 0 zurückgeben? hallo beginnt nämlich bei index 0 oder bin ich da falsch?
mfg geisi
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

Re: in strings suchen

  Alt 17. Okt 2005, 22:37
Das erste Zeichen eines String steht an der Stelle [1].
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.153 Beiträge
 
Delphi 12 Athens
 
#5

Re: in strings suchen

  Alt 17. Okt 2005, 22:57
Die Strings sind ja in gewisser Weise auch nur Arrays of Char (vorallem die LongStrings ^^), aber da bei den ersten Strings, dem ShortString, als erstes das LängenByte vorhanden war (was jetzt allerdings nicht mehr indieser Art existiert), befand/befindet sich das 1. Zeichen eben auf Position 1 - eben alles um ein Feld verschoben.


ich hoffe dat war jetzt verständlich erklärt und möglichst fehlerfrei ._.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Christian Seehase
(Co-Admin)

Registriert seit: 29. Mai 2002
Ort: Hamburg
11.105 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: in strings suchen

  Alt 17. Okt 2005, 23:04
Moin Himitsu,

Zitat von himitsu:
als erstes das LängenByte vorhanden war (was jetzt allerdings nicht mehr indieser Art existiert)
Kommt drauf an, was Du als "nicht mehr in dieser Art" ansiehst.
Jetzt ist der Zähler ein Integer, der auf den Postionen String bis String-3 liegt, in negativer Richtung gefolgt von einem, ebenfalls 32 Bit grossen, Referenzzähler.
Tschüss Chris
Die drei Feinde des Programmierers: Sonne, Frischluft und dieses unerträgliche Gebrüll der Vögel.
Der Klügere gibt solange nach bis er der Dumme ist
  Mit Zitat antworten Zitat
ripper8472

Registriert seit: 17. Aug 2003
275 Beiträge
 
#7

Re: in strings suchen

  Alt 17. Okt 2005, 23:30
die "neuen" strings sind auch mit einem \0 terminiert, damit man sie problemlos nach pchar casten kann
Christoph
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.153 Beiträge
 
Delphi 12 Athens
 
#8

Re: in strings suchen

  Alt 18. Okt 2005, 00:13
Zitat von Christian Seehase:
Kommt drauf an, was Du als "nicht mehr in dieser Art" ansiehst.
Jetzt ist der Zähler ein Integer, der auf den Postionen String bis String-3 liegt, in negativer Richtung gefolgt von einem, ebenfalls 32 Bit grossen, Referenzzähler.
Genau das meinte ich ja

Delphi-Quellcode:
Const SDynArrayInfoR = 2 * SizeOf(LongInt);
  SDynArrayInfo = SizeOf(LongInt) + SDynArrayInfoR;

Type TShortStringInfo = packed Record
    Length: Byte;
    Chars: packed Array[1..255{or 1..Length}] of Char;
  End;

  TDynArrayInfo = packed Record
    MemoryInfo: LongInt;
    RefCount: LongInt;
    ElementCount: LongInt;
    Data: packed Array[0..0{High(LongInt) - SDynArrayInfo - 1}] of Byte;
  End;

  TAnsiStringInfo = packed Record
    MemoryInfo: LongInt;
    RefCount: LongInt;
    ElementCount: LongInt;
    Data: packed Array[1..High((LongInt) - SDynArrayInfo] of AnsiChar;
  End;

  TWideStringInfo = packed Record
    MemoryInfo: LongInt;
    RefCount: LongInt;
    ElementCount: LongInt;
    Data: packed Array[1..(High((LongInt) - SDynArrayInfo) div 2] of WideChar;
  End;
Der Unterschied ist halt, daß es das LängenByte(an sich) ja nicht mehr gibt,
außerdem zeigt jetzt der Pointer of Typ auf das 1. Zeichen und nicht mehr auf das LängenByte (wie beim ShortString).

@S beim ShortString zeigt auf TShortStringInfo.Length,
wärend bei den anderen Typen Pointer(S) auf Typ.Data verweist.



Komplett sieht das Ganze dann so bei mir aus:
Delphi-Quellcode:
(***************************************************************************************)
(*** Compiler Intern Data-Types ********************************************************)
(***************************************************************************************)

Type TShortStringInfo = packed Record // PShortStringInfo := @Var
    Length: Byte;
    Chars: packed Array[1..255{or 1..Length}] of Char;
  End;
  PShortStringInfo = ^TShortStringInfo;

(*************************************************************************** )
(                                                                            )
(  P___Info[C]  := Pointer(var) - SDynArrayInfo                              )
(  Pointer(var) := T___Info[C].___Addr                                      )
(                                                                            )
(  A String/AnsiString is an Array of Char and just the same as near the    )
(  Array of Char an additional #0 is attached also there still behind.      )
(  (for the PChar compatibility)                                            )
(                                                                            )
(  The WideString and the Array of WideChar are also identical              )
(  and there #0#0 hide themselves behind that.                              )
(                                                                            )
(*************************************************************************** )
(                                                                            )
(  T___Info / P___Info:                                                      )
(  ********************                                                      )
(                                                                            )
(  Pointer(var)      = nil        > nil {in EXE}        > nil {in RAM}      )
(                                                                            )
(  MemoryInfo        -            -                    <> 0                )
(  RefCount          -            = -1                  >= 1                )
(  ElementCount      -            = Length(var)        = Length(var)      )
(  Data              -            = var                = var              )
(                                                                            )
(*************************************************************************** )
(                                                                            )
(  T___InfoC / P___InfoC:                                                    )
(  **********************                                                    )
(                                                                            )
(  Pointer(var)      = nil      > nil {in EXE}        > nil {in RAM}      )
(                                                                            )
(  MemoryInfo        = 0        = 0                    <> 0                )
(  RefCount          = 0        = -1                  >= 1                )
(  ElementCount      = 0        >= 1 = Length(var)    >= 1 = Length(var)  )
(  Data              -          = var                  = var              )
(                                                                            )
(****************************************************************************)


{ No Type }
{}Const SDynArrayInfoR = 2 * SizeOf(LongInt);
{}  SDynArrayInfo = SizeOf(LongInt) + SDynArrayInfoR;
{}Type TDynArrayInfo = packed Record
{}    MemoryInfo: LongInt;
{}    RefCount: LongInt;
{}    ElementCount: LongInt;
{}    Data: packed Array[0..0{High(Integer) - SDynArrayInfo - 1}] of Byte;
{}  End;

Type PDynArrayInfo = ^TDynArrayInfo;
  TDynArrayInfoC = packed Record
    MemoryInfo: LongInt;
    RefCount: LongInt;
    ElementCount: LongInt;
    DataAddr: Pointer;
    isVar: LongBool;
  End;

{ No Types }
{}Type TAnsiStringInfo = packed Record
{}    MemoryInfo: LongInt;
{}    RefCount: LongInt;
{}    ElementCount: LongInt;
{}    Data: packed Array[1..High(Integer) - SDynArrayInfo] of AnsiChar;
{}  End;
{}  TWideStringInfo = packed Record
{}    MemoryInfo: LongInt;
{}    RefCount: LongInt;
{}    ElementCount: LongInt;
{}    Data: packed Array[1..(High(Integer) - SDynArrayInfo) div 2] of WideChar;
{}  End;

Type PAnsiStringInfo = ^TAnsiStringInfo;
  TAnsiStringInfoC = packed Record
    MemoryInfo: LongInt;
    RefCount: LongInt;
    ElementCount: LongInt;
    DataAddr: PAnsiChar;
    isVar: LongBool;
  End;

  PWideStringInfo = ^TWideStringInfo;
  TWideStringInfoC = packed Record
    MemoryInfo: LongInt;
    RefCount: LongInt;
    ElementCount: LongInt;
    DataAddr: PWideChar;
    isVar: LongBool;
  End;

Function DynArrayInfo (Const A): PDynArrayInfo;
Function DynArrayInfoC(Const A): TDynArrayInfoC;

Function StringInfo (Const S: AnsiString): PAnsiStringInfo; Overload;
Function StringInfoC(Const S: AnsiString): TAnsiStringInfoC; Overload;

{$IFNDEF UseOLEWideString}
  Function StringInfo (Const S: WideString): PWideStringInfo; Overload;
  Function StringInfoC(Const S: WideString): TWideStringInfoC; Overload;
{$ENDIF}

Achtung: Die Typen für WideStrings bitte nicht ganz so ernst nehmen, denn aus unerfindlichen Gründen ist die aktuell implementierte Version der WideStrings nicht von Borland definiert worden - es wird einfach ein OLEWideString verwendet, welcher etwas anders aufgebaut ist.
Dieses ist auch der Hauptgrund, weßhalb WideStrings nicht über eine Referenzzählung verfügen.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:10 Uhr.
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