Registriert seit: 28. Mär 2012
103 Beiträge
|
AW: CSV anpassen
17. Jan 2021, 14:38
Sicher führen viele Wege nach Rom. Hier ist einer davon:
Delphi-Quellcode:
procedure TSIPForm.Test;
var Line, aWord : String;
A : Array [1..6] of String;
I, K, L : Integer;
function GetNextWord(var S:String):String;
var P:Integer;
begin
Result:='';
P:=Pos(#32, S);
if (P > 0) then
begin
Result:=Copy(S, 1, P - 1);
Delete(S, 1, P);
end;
end;
begin
RichEdit.Clear;
RichEdit.Lines.Add('Herr Mustermann mit');
RichEdit.Lines.Add('Herr Mustermann, Max mit');
RichEdit.Lines.Add('Herr Dr. Mustermann mit');
RichEdit.Lines.Add('Herr Dr. Mustermann, Max mit');
RichEdit.Lines.Add('Herr Prof. Dr. Mustermann mit');
RichEdit.Lines.Add('Herr Prof. Dr. Mustermann, Max mit');
RichEdit.Lines.Add('');
for L:=0 to RichEdit.Lines.Count - 1 do if (RichEdit.Lines[L] > '') then
begin
Line:=RichEdit.Lines[L];
for I:=1 to 6 do A[I]:='';
repeat
aWord:=GetNextWord(Line);
if (aWord > '') then
begin
if (A[1] = '') then A[1]:=aWord
else
begin
if (aWord = 'Prof.') or (aWord = 'Dr.') then
begin
if (A[2] = '') then A[2]:=aWord else A[3]:=aWord;
end
else
begin
K:=Pos(',', aWord);
if (K > 0) then Delete(aWord, K, 1);
if (A[4] = '') then A[4]:=aWord else A[5]:=aWord;
end;
end;
end;
A[6]:='mit';
until (aWord = '');
Line:='';
for I:=1 to 6 do Line:=Line + A[I] + ';';
Delete(Line, Length(Line), 1);
RichEdit.Lines.Add(Line);
end;
end;
|
|
Zitat
|