![]() |
Re: Wort nach einem Wort
Ich hab dafür zwei sehr lieb gewonnene Funktionen (braucht man wirklich oft):
Delphi-Quellcode:
Lösung zu deiner Frage:
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;
Delphi-Quellcode:
hth,
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 Ralf |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz