Показать полную графическую версию : [решено] Обрезать строку до указанного символа
Имеется файл вида:
61.172.246.180:80
61.172.249.94:80
61.172.249.96:80
62.233.138.180:3128
66.98.212.79:8888
Хотелось бы получить 2 файла
Первый:
61.172.246.180
61.172.249.94
61.172.249.96
62.233.138.180
66.98.212.79
Второй:
80
80
80
3128
8888
То есть необходима функция обрезающая строку до указанного символа ":" с левой стороны затем с правой..
Буду рад любой помощи..
Frost_Imp
25-09-2009, 15:19
мммм, вставить в эксель и сделать "текст по столбцам" =)
Руками или средствами AutoIt - дело вкуса)
необходима функция обрезающая строку до указанного символа ":" с левой стороны затем с правой »
Причём у каждой строки, вот пример с использованием StringRegExp:
$sInFile = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & "\File.txt"
$sOutFile_IPs = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & "\IPs.txt"
$sOutFile_Ports = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & "\Ports.txt"
$sReadFile = FileRead (http://www.autoitscript.com/autoit3/docs/functions/FileRead.htm)($sInFile)
$aRet = StringRegExp (http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm)($sReadFile, '((?:[0-9]{1,3}\.?){4}):([0-9]{1,4})', 3)
$sOutFile_IPs_Content = ""
$sOutFile_Ports_Content = ""
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) UBound (http://www.autoitscript.com/autoit3/docs/functions/UBound.htm)($aRet)-1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Mod (http://www.autoitscript.com/autoit3/docs/functions/Mod.htm)($i, 2) = 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) ;Чётное число (или 0), пишем IP'шки
$sOutFile_IPs_Content &= $aRet[$i] & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else) ;Иначе пишем порты
$sOutFile_Ports_Content &= $aRet[$i] & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
$hFile = FileOpen (http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm)($sOutFile_IPs, 2)
FileWrite (http://www.autoitscript.com/autoit3/docs/functions/FileWrite.htm)($hFile, $sOutFile_IPs_Content)
FileClose (http://www.autoitscript.com/autoit3/docs/functions/FileClose.htm)($hFile)
$hFile = FileOpen (http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm)($sOutFile_Ports, 2)
FileWrite (http://www.autoitscript.com/autoit3/docs/functions/FileWrite.htm)($hFile, $sOutFile_Ports_Content)
FileClose (http://www.autoitscript.com/autoit3/docs/functions/FileClose.htm)($hFile)
вставить в эксель и сделать "текст по столбцам" »
Такие советы лучше не озвучивать, они бессмыслены.
Думаю, из файла сами считаете... так же как и положите. Или посмотрите примеры. Берем адрес и порт из строки таким образом:
$s="61.172.246.180:80"
$pos=StringInStr($s,":")
MsgBox(0,"",StringLeft($s,$pos-1));
MsgBox(0,"",StringMid($s,$pos+1,StringLen($s)-$pos))
ну или
$aLine = StringSplit($sLine, ':')
$sIP = $aLine[1]
$sPort = $aLine[2]
kaster, оу :) Признаю, у вас красивее :)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.