Autor Beitrag
Olli_Sahr
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 83


D5 Prof, D7 Architect
BeitragVerfasst: Mo 27.02.06 12:56 
Hallo,

gibt es eine fertige Funktion, die mir sagt, wie oft ein Zeichen in einem String vorkommt?
Oder muss ich mir da selber was basteln?
Basteln ist kein Problem, aber es wäre blöd eine bereits existierende Funktion nachzuprogrammieren.....

Gruß


OLLI
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 27.02.06 13:05 
Such mal nach Suche in: Delphi-Forum, Delphi-Library POSEX

AXMD
Olli_Sahr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 83


D5 Prof, D7 Architect
BeitragVerfasst: Mo 27.02.06 13:13 
Hallo,

PosEx gibt mit ja die Position und nicht die Anzahl....

ich habe momentan folgende Funktion:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function AnzahlZeichenInString(aString: string; aZeichen: char): integer;
var counter: integer;
begin
   result := 0;
   for counter := 1 to length(aString) do
      if (aString[counter] = aZeichen) then inc(Result);
end;


Gibt es dafür was kürzeren (eine vordefinierte Funktion) ?

Danke und Gruß


OLLI
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 27.02.06 13:58 
Moin!

Wenn du das für mehrere Zeichen hintereinander machen musst, dann bietet sich auch eine Histogrammfunktion an:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
type
  TCharHisto = Array[0..255of Integer;

var
  Histo: TCharHisto;

procedure CharHisto(const S: Stringvar Histo: TCharHisto);
  var
    i: Integer;
begin
  ZeroMemory(@Histo,SizeOf(Histo));
  for i := 1 to Length(S) do
    Inc(Histo[Ord(S[i])]);
end;

CharHisto('Das ist ein Test!',Histo);
ShowMessage(IntToStr(Histo[Ord('e')]));

cu
Narses