Posted July 16, 201510 yr how to get URLs in memo, delimited text or split?e.g: in memo.text : begin memo1.lines.text := ' rtadgjkjuouioop hxxp://exmpl.com yyhfhjjj ijoo hxxp://wxw.exmpl.org iolvb wxw.exmpl.comiiij fiuddhityftp://exmpl.com uiufsftgco45788 hxxps://exmpl.com ggcghj hxxps://wxw.exmpl.net giiu'; end;result in memo 2I mean like this code: function spliter(const s : string; ts, rs : tstrings) : string; var i : integer; begin for i := 0 to rs.count - 1 do begin if (pos('wxw', ts.strings) > 0) or (pos('fxp://', ts.strings) > 0) or (pos('hxxp://', ts.strings) > 0) or (pos('hxxps://', ts.strings) > 0) or (pos('hxxp://wxw', ts.strings) > 0) or (pos('hxxps://wxw', ts.strings) > 0) then begin result := ''; blah blah blah etc end; rs.text := result; end;on button click spliter(edit1.text, memo1.lines, memo2.lines);
July 17, 201510 yr Use a regular expression instead of multiple compares something like this works great for a URL... (From RegexBuddys library) \b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]But beware, a regex or any sort of compare will never be 100% accurate for a URL because a URL can contain most characters, especially if you are trying to filter spam and the poster is trying to bypass the filter...
July 18, 201510 yr I'm not sure what you asking but if your asking how to match / extract the link in your example ' to' then use a regex again, something like this... a.?href="'(.+)'"
July 19, 201510 yr Author oh sorry still chaos pharsing html script Edited July 20, 201510 yr by X-88
September 5, 20159 yr if you want to use pos then use it with the '://' string - 4 chars for the beginning and the last '.' + 3 chars for the end per line, this should yield full url. regular expressions would be the best way for this and the more correct way to do it.
Create an account or sign in to comment