ffdshow Posted June 2, 2010 Share Posted June 2, 2010 (edited) I have a text file which contains one link per line, but the links are prefixed and suffixed with some characters. The suffixes are not a problem since they all contains exactly 20 characters. Prefixes contains different number of characters. Example: ghjgrjd.rar;http://www.netload.in/dateiGivoLSefgq/ghjgrjd.rar.htm;100 MB;2;31.05.2010 wrdrtv.rar;http://www.netload.in/dateixXm3I1wopv/wrdrtv.rar.htm;100 MB;2;31.05.2010 The problem is that the prefixes have different length from line to line and a script like this $inputfile = FileOpen(@ScriptDir & "\input.txt", 0) $outputfile = FileOpen(@ScriptDir & "\output.txt", 1) While 1 $line = FileReadLine($inputfile) If @error Then ExitLoop $result = StringTrimLeft($line, 12) If StringLen($line) = 0 Then FileWriteLine ($outputfile, "") If StringLen($line) > 0 Then FileWriteLine ($outputfile, $result) Wend FileClose ($inputfile) FileClose ($outputfile) will not help. Is possible to extract all links to a text file (one link per line) ? Edited June 2, 2010 by ffdshow Link to comment Share on other sites More sharing options...
somdcomputerguy Posted June 2, 2010 Share Posted June 2, 2010 If those semicolons are consistent, use StringSplit. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
UEZ Posted June 2, 2010 Share Posted June 2, 2010 (edited) One possibility might be this: $inputfile = FileOpen(@ScriptDir & "\input.txt", 0) $outputfile = FileOpen(@ScriptDir & "\output.txt", 1) Global $o While 1 $line = FileReadLine($inputfile) If @error Then ExitLoop $aRegEx = StringRegExp($line, ';(http:\/\/.*);.*;.*;', 1) If IsArray($aRegEx) Then $o &= $aRegEx[0] & @CRLF Wend FileWrite($outputfile, $o) FileClose ($inputfile) FileClose ($outputfile) BR, UEZ Edited June 2, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
ffdshow Posted June 2, 2010 Author Share Posted June 2, 2010 Thanks UEZ! Works fine. Link to comment Share on other sites More sharing options...
EnderWiggin Posted June 21, 2010 Share Posted June 21, 2010 One possibility might be this: $inputfile = FileOpen(@ScriptDir & "\input.txt", 0) $outputfile = FileOpen(@ScriptDir & "\output.txt", 1) Global $o While 1 $line = FileReadLine($inputfile) If @error Then ExitLoop $aRegEx = StringRegExp($line, ';(http:\/\/.*);.*;.*;', 1) If IsArray($aRegEx) Then $o &= $aRegEx[0] & @CRLF Wend FileWrite($outputfile, $o) FileClose ($inputfile) FileClose ($outputfile) BR, UEZ This code example was useful to me as well; thanks very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now