Problem mozes resiti na primer ovako... Na formi imas
Memo1,
Memo2 i
Button1. Ovo je tvoja prepravljena funkcija
ExtractText():
Code:
function ExtractText(const Str, Delim1, Delim2: string; PosStart: integer; var PosEnd: integer): string;
var
pos1, pos2: integer;
begin
Result := '';
pos1 := PosEx(Delim1, Str, PosStart);
if pos1 > 0 then
begin
pos2 := PosEx(Delim2, Str, pos1 + Length(Delim1));
if pos2 > 0 then
begin
PosEnd := pos2 + Length(Delim2);
Result := Copy(Str, pos1 + Length(Delim1), pos2 - (pos1 + Length(Delim1)));
end;
end;
end;
Na
OnClick dogadjaj dugmeta stavis ovaj kod:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var Pos: integer;
sText: string;
begin
sText := ExtractText(Memo1.Lines.Text, '"url":"', '","visibleUrl"', 1, Pos);
while sText <> '' do
begin
Memo2.Lines.Add(sText);
sText := ExtractText(Memo1.Lines.Text, '"url":"', '","visibleUrl"', Pos, Pos);
end;
end;
I to je to. Kada u
Memo1 imas ovo sto si naveo (
http://ajax.googleapis.com/aja...tart=1&rsz=large&q=max)...
Code:
{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://sbooth.org/Max/","url":"http://sbooth.org/Max/","visibleUrl":"sbooth.org","cacheUrl":"http://www.google.com/search?q\u003dcache:YUC_ZQ9YhH8J:sbooth.org","title":"\u003cb\u003eMax\u003c/b\u003e from sbooth.org","titleNoFormatting":"Max from sbooth.org","content":"When extracting audio from compact discs, \u003cb\u003eMax\u003c/b\u003e offers the maximum in flexibility to ensure the true sound of your CD is faithfully extracted. For pristine discs, \u003cb\u003eMax\u003c/b\u003e \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.maxgames.com/","url":"http://www.maxgames.com/","visibleUrl":"www.maxgames.com","cacheUrl":"http://www.google.com/search?q\u003dcache:F6n3Q-mu0REJ:www.maxgames.com","title":"\u003cb\u003eMax\u003c/b\u003e Games : Free internet games to the \u003cb\u003eMax\u003c/b\u003e","titleNoFormatting":"Max Games : Free internet games to the Max","content":"New \u003cb\u003eMax\u003c/b\u003e Games \u003cb\u003e...\u003c/b\u003e \u003cb\u003eMax\u003c/b\u003e Dirt Bike \u003cb\u003e....\u003c/b\u003e \u003cb\u003eMax\u003c/b\u003e Dirt Bike 2 · \u003cb\u003eMax\u003c/b\u003e Dirt Truck · \u003cb\u003eMax\u003c/b\u003e Mesiria RPG 1 · \u003cb\u003eMax\u003c/b\u003e Mesiria RPG 2 · \u003cb\u003eMax\u003c/b\u003e Mesiria RPG 3 · McDonalds Videogame \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.cinemax.com/","url":"http://www.cinemax.com/","visibleUrl":"www.cinemax.com","cacheUrl":"http://www.google.com/search?q\u003dcache:Qr5NES_LpPkJ:www.cinemax.com","title":"Cinemax.com - Official Website Featuring Movies and Original Series","titleNoFormatting":"Cinemax.com - Official Website Featuring Movies and Original Series","content":"The official website of Cinemax, home of Hollywood hits and action-packed original series. Find good movies and TV shows to watch online, from action, \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.max-ny.com/","url":"http://www.max-ny.com/","visibleUrl":"www.max-ny.com","cacheUrl":"http://www.google.com/search?q\u003dcache:-GjKt8w-SHAJ:www.max-ny.com","title":"\u003cb\u003eMax\u003c/b\u003e restaurant","titleNoFormatting":"Max restaurant","content":"2010 \u003cb\u003eMax\u003c/b\u003e Restaurant, all rights reserved."},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://max.adobe.com/","url":"http://max.adobe.com/","visibleUrl":"max.adobe.com","cacheUrl":"http://www.google.com/search?q\u003dcache:V7aoUf95KzIJ:max.adobe.com","title":"Adobe \u003cb\u003eMAX\u003c/b\u003e","titleNoFormatting":"Adobe MAX","content":"Save the date! Join us for \u003cb\u003eMAX\u003c/b\u003e 2012 taking place. October 20–24 in Los Angeles Save it to your calendar \u0026gt;. \u003cb\u003eMAX\u003c/b\u003e Online. Experience some of the excitement of \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.imdb.com/title/tt0290210/","url":"http://www.imdb.com/title/tt0290210/","visibleUrl":"www.imdb.com","cacheUrl":"http://www.google.com/search?q\u003dcache:I7eYK1p00iwJ:www.imdb.com","title":"\u003cb\u003eMax\u003c/b\u003e (2002) - IMDb","titleNoFormatting":"Max (2002) - IMDb","content":"Directed by Menno Meyjes. With John Cusack, Noah Taylor, Leelee Sobieski, Molly Parker. A film studying the depiction of a friendship between an art dealer \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.modestoareaexpress.com/","url":"http://www.modestoareaexpress.com/","visibleUrl":"www.modestoareaexpress.com","cacheUrl":"http://www.google.com/search?q\u003dcache:8eXIHHW8_XMJ:www.modestoareaexpress.com","title":"Modesto Area Express (\u003cb\u003eMAX\u003c/b\u003e)","titleNoFormatting":"Modesto Area Express (MAX)","content":"Bus transportation, dial-a-ride (demand response paratransit) and commuter services. Includes information on connecting services with Amtrak, BART, and \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://cycling74.com/products/maxmspjitter/","url":"http://cycling74.com/products/maxmspjitter/","visibleUrl":"cycling74.com","cacheUrl":"http://www.google.com/search?q\u003dcache:ObjbybDdMwUJ:cycling74.com","title":"\u003cb\u003eMax\u003c/b\u003e « Cycling 74","titleNoFormatting":"Max « Cycling 74","content":"For over twenty years, \u003cb\u003eMax\u003c/b\u003e has been used by performers, artists, and composers to make cutting-edge work by connecting basic functional blocks together into \u003cb\u003e...\u003c/b\u003e"}],"cursor":{"resultCount":"182,000,000","pages":[{"start":"0","label":1},{"start":"8","label":2},{"start":"16","label":3},{"start":"24","label":4},{"start":"32","label":5},{"start":"40","label":6},{"start":"48","label":7},{"start":"56","label":8}],"estimatedResultCount":"182000000","currentPageIndex":0,"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d1\u0026hl\u003den\u0026q\u003dmax","searchResultTime":"0.10"}}, "responseDetails": null, "responseStatus": 200}
... pritiskom na dugme na formi, u
Memo2 ce ti se pojaviti ovo:
Code:
http://sbooth.org/Max/
http://www.maxgames.com/
http://www.cinemax.com/
http://www.max-ny.com/
http://max.adobe.com/
http://www.imdb.com/title/tt0290210/
http://www.modestoareaexpress.com/
http://cycling74.com/products/maxmspjitter/
Prikacio sam ti uz ovu poruku i kompletan source, sa sve kompajliranim izvrsnim programom, da vidis kako radi.
Na kraju samo jedan drugarski savet... ;) Trudi se da sto vise mislis svojom glavom, ako hoces da se bavis programiranjem to je jako bitno (da ne kazem presudno). Ovo resenje koje sam ti postavio si i sam mogao da napravis, obzirom da si vec prethodno koristio
PosEx() funkciju u svojoj
ExtractText() funkciji, samo je bilo potrebno da razmislis na koji nacin mozes da odradis to sto tebi treba. Moje resenje nije jedino, i sigurno nije ni najbolje, ali radi, i moze ti posluziti da nesto novo naucis i mozda i sam osmislis bolje resenje - ako ne za konkretno ovaj problem, onda za neki naredni.
Inace nije praksa da se daju gotova resenja, pogotovo ne za relativno lake probleme, ali eto, imao sam visak vremena i ovo mi je doslo kao zanimacija, nadam se da ce ti koristiti. Ako nesto nije jasno a voleo bi da razjasnis (naucis), slobodno pitaj.
'Ajd', pa puno srece u daljem programiranju =)