Registriert seit: 30. Mai 2007
489 Beiträge
Delphi 2010 Professional
|
Re: Wort nach einem Wort
24. Feb 2009, 13:29
Ich hab dafür zwei sehr lieb gewonnene Funktionen (braucht man wirklich oft):
Delphi-Quellcode:
function FirstWord(var WorkStr : String; Cut : boolean) : string;
// Gives back first parameter in String
// if requested (CUT=TRUE) this word is being cut off the original
// string
// Leading spaces are NOT corrected (if necessary : TRIM)
begin
result:=FirstWordSeparator(' ',WorkStr,Cut);
// single words can be separated by several spaces
if Cut then
WorkStr:=Trim(WorkStr);
end;
function FirstWordSeparator(sep : string;var WorkStr : String; Cut : boolean) : string;
// Gives back first parameter delimited by "sep" in String
// If requested (CUT=TRUE) result+separator are removed from the original string
// If Separator is NOT found in WorkStr and Cut=True, then WorkStr:=''
var counter : integer;
begin
counter:=pos(sep,WorkStr); // "abcXdef" -> counter=4
if counter>0
then result:=copy(WorkStr,1,counter-1)
else result:=WorkStr;
if Cut then
begin
if counter>0
then delete(WorkStr,1,counter+length(sep)-1)
else WorkStr:='';
end;
end;
Lösung zu deiner Frage:
Delphi-Quellcode:
var s : string;
Cmd : string;
begin
// ... s enthält irgendwas wie "blabla Kommando Params"
FirstWord(s, True); // Erstes Wort (blabla) wegschneiden.
Cmd:=FirstWord(s, True); // Cmd = Kommando
// s enthält den "Reststring", also die Params
hth,
Ralf
|
|
Zitat
|