Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Wort nach einem Wort (https://www.delphipraxis.net/129680-wort-nach-einem-wort.html)

ralfiii 24. Feb 2009 12:29

Re: Wort nach einem Wort
 
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


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:12 Uhr.
Seite 3 von 3     123   

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