AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Extract word from string

Ein Thema von Razor · begonnen am 13. Feb 2009 · letzter Beitrag vom 13. Feb 2009
Antwort Antwort
Razor
(Gast)

n/a Beiträge
 
#1

Extract word from string

  Alt 13. Feb 2009, 12:57
How to do it,for example
i want to extract some specific string from tlistbox.

Items are:

100x200
200x300
1280x2000

if its listbox.items.strings[3}:='1280x2000' then i want to just extract only 1280 or 2000 from 1280x2000?


Is it possible?
  Mit Zitat antworten Zitat
nahpets
(Gast)

n/a Beiträge
 
#2

Re: Extract word from string

  Alt 13. Feb 2009, 13:05
Hallo,

Delphi-Quellcode:
Var
  iPos : Integer;
  i1280 : Integer;
  i2000 : Integer;
begin
  iPos := Pos('x',listbox.items.strings[3]);
  i1280 := StrToIntDef(Copy(listbox.items.strings[3],1,iPos - 1),0);
  i2000 := StrToIntDef(Copy(listbox.items.strings[3],iPos + 1,255),0);
end;
  Mit Zitat antworten Zitat
Benutzerbild von GPRSNerd
GPRSNerd

Registriert seit: 30. Dez 2004
Ort: Ruhrpott
239 Beiträge
 
Delphi 10.4 Sydney
 
#3

Re: Extract word from string

  Alt 13. Feb 2009, 13:15
Something like this will do for the 1st and the 2nd number, assumed that they are always separated by an x:

Delphi-Quellcode:
copy(listbox.items.strings[3], 1, pos('x', listbox.items.strings[3])-1);
copy(listbox.items.strings[3], pos('x', listbox.items.strings[3])+1), MAX_INT);
Stefan
  Mit Zitat antworten Zitat
Benutzerbild von stoxx
stoxx

Registriert seit: 13. Aug 2003
1.111 Beiträge
 
#4

Re: Extract word from string

  Alt 13. Feb 2009, 13:25
Or a general solution ...


Delphi-Quellcode:
function GetStringNr(const NR : integer; const Value : AnsiString; const delim : char = ';'): Ansistring;
var i, idx : integer;
    iOrd : byte;
    Res : AnsiString;
    Used : Integer;
begin
  Result := '';
  idx := 1;
  Used := 0;
  SetLength(Res, Length(Value));

  for i := 1 to length(Value) do
  begin
    if Value[i] = delim then
       begin
          inc(IDX);
          continue;
       end;
    If IDX > NR then break;
    if IDX = NR then
     begin
      inc(Used);
      Res[used] := Value[i];
     end;
  end; // von for
   SetLength(Res, Used);
   result := res;
end; // von GetStringNRh

//==============================================================================


procedure TForm1.Button1Click(Sender : TObject);
var Value1 : String;
    Value2 : String;
begin

Value1 := GetStringNR(1, listbox.items.strings[3], 'x');
Value2 := GetStringNR(2, listbox.items.strings[3], 'x');


end;
Phantasie ist etwas, was sich manche Leute gar nicht vorstellen können.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz