-2

I am looking for a way to return a url as a string from the current Internet Explorer URL.

This approach uses dde. It very fast and works well except it returns a very long string in two parts both with quotes.

uses
  ddeman;

function GetURL(Service: string): string;
var
  ClDDE: TDDEClientConv;
  temp: PAnsiChar;
begin
  Result := '';
  ClDDE := TDDEClientConv.Create(nil);
  with ClDDE do
  begin
    SetLink(Service, 'WWW_GetWindowInfo');
    temp := RequestData('0xFFFFFFFF');
    Result := StrPas(temp);
    StrDispose(temp);
    CloseLink;
  end;
  ClDDE.Free;
end;

For example this returns: "http://core2.staticworld.net/images/article/2014/01/counterfeit_android_apps1-100227383-medium.jpg","http://core2.staticworld.net/images/article/2014/01/counterfeit_android_apps1-100227383-medium.jpg"

But I am looking for just the first part before the first comma without the quotes: http://core2.staticworld.net/images/article/2014/01/counterfeit_android_apps1-100227383-medium.jpg

Any suggestions for another approach or how to parse the string to produce the result shown without quotes and just the first part of the string?

Gerry Coll
  • 5,867
  • 1
  • 27
  • 36
Bill
  • 2,993
  • 5
  • 37
  • 71

1 Answers1

2

You can parse the string pretty simply yourself:

// Extract string up to position of the ,
Temp := Copy(Temp, 1, Pos(',', Temp) - 1);
// Remove double-quotes from resulting string
Temp := StringReplace(temp, '"', '', [rfReplaceAll]);

Here's a sample console app that uses the logic above on the sample response you provided, and outputs the final contents to the console:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  LinkStr = '"http://core2.staticworld.net/images/article/2014/01/counterfeit_android_apps1-100227383-medium.jpg","http://core2.staticworld.net/images/article/2014/01/counterfeit_android_apps1-100227383-medium.jpg"';

var
  Temp: string;

begin
  Temp := Copy(LinkStr, 1, Pos(',', LinkStr) - 1);
  Temp := StringReplace(Temp, '"', '', [rfReplaceAll]);
  Writeln('After: ' + Temp);
  ReadLn;
end.

Output:

enter image description here

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • @Ken... the quotes are removed ok, but unfortunately the entire string is returned instead of the first part of the string before the comma. – Bill Apr 10 '14 at 21:11
  • @Bill: That's not true. See my edited answer, which uses the **exact** string you provided (I copied and pasted it), and outputs just the first portion (up to the comma) with the quotes removed. – Ken White Apr 10 '14 at 22:05
  • It would be nice to know if there are alternatives to using dde for this as well. Thanks Ken for your assistance. – Bill Apr 10 '14 at 22:22
  • @Bill: You asked for either/or. I didn't have an answer to the first, but the parsing was easy. :-) As you say it's "very fast and works well", and the parsing code is also very fast and works well... ? – Ken White Apr 10 '14 at 22:25