Показать полную графическую версию : Поиск слова в txt затем поиск по маске "(383)" и вывод инфы
Всем привет!
Помогите написать функцию Поиск слова в txt затем поиск по маске "(383)" и вывод инфы в GUI - Имя - номер телефона
Есть текстовик с именами и номерами телефонов, если ищем имя то не всегда сразу , бывает после какого-то комментария имеется номер
madmasles
27-09-2011, 15:01
rustoss,
Приведите образец текста, в котором искать надо и конкретный результат, который должен быть найден.
"Ирина Петровна Васильева - нянечка, Уральская 104 8(383)2-56-54-89 "
В окне ввожу фамилию, кнопка получить, и высвечивается Фамилия и номер телефона
Gui как-то так
$Gui = GUICreate("Смотрим Номер телефона", 420, 100)
$Label2 = GUICtrlCreateLabel("Введите имя ", 10, 10, 186, 17)
$Input2 = GUICtrlCreateInput("", 10, 27, 400, 21)
$folder2 = GUICtrlCreateButton("Получить", 340, 55, 70, 23)
$info = GUICtrlCreateLabel ("", 10,60,320,34)
madmasles
27-09-2011, 16:29
rustoss,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
$sFile = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\TLF.txt'
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) FileExists (http://www.autoitscript.com/autoit3/docs/functions/FileExists.htm)($sFile) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(16, 'Error', 'No File')
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$sText = FileRead (http://www.autoitscript.com/autoit3/docs/functions/FileRead.htm)($sFile)
$aFIO = StringRegExp (http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm)($sText, '([А-Яа-яЁё]+?\h[А-Яа-яЁё]+?\h[А-Яа-яЁё]+?)\h', 3)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(16, 'Error', 'StringRegExp')
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$sFIO = ''
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)($aFIO) - 1
$sFIO &= $aFIO[$i] & '|'
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
$aFIO = 0
GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Смотрим Номер телефона', 420, 100)
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('Выберите имя', 10, 10, 186, 17)
$nCombo = GUICtrlCreateCombo (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateCombo.htm)('', 10, 27, 400, 21)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)(-1, $sFIO)
$nGet = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Получить', 340, 55, 70, 23)
$nTLF = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('', 10, 60, 320, 34)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
$sFIO = ''
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nCombo, $nGet
$sSearch = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nCombo)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sSearch Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$sNum = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sText & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@crlf), '(?s).*?' & $sSearch & '.*?(\d\(\d{3}\).*?\d)\r?\n.*', '\1')
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @extended (http://www.autoitscript.com/autoit3/docs/macros.htm#@extended) = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nTLF, $sNum)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Отлично!!!!!
Работает только с русским языком
madmasles
27-09-2011, 17:16
Работает только с русским языком »
"Ирина Петровна Васильева - нянечка, Уральская 104 8(383)2-56-54-89 " »А где в примере текста другой?
нету согласен, просто в контактах есть,
вот сейчас экспериментирую, но темный лес....
это
$aFIO = StringRegExp($sText, '([A-Za-z]+?\h[A-Za-z]+?\h[A-Za-z]+?)\h', 3)
ФИО переписал [A-Za-z] как совместить еще и русский?
тут бы еще понять...
$sNum = StringRegExpReplace($sText & @CRLF, '(?s).*?' & $sSearch & '.*?(\d\(\d{3}\).*?\d)\r?\n.*', '\1')
(\d{3}\) - 3 цифры в скобках?
если переписать все в формат 8(383)2-56-54-89 то находит
есть еще номера 8-800
(383) 2 54-89-72 и по разному записаны
попробую текстовик под один шаблон перебить.
madmasles
27-09-2011, 19:11
просто в контактах есть »
есть еще номера 8-800 »Я ведь Вас просил образец текста. Дайте все возможные варианты.
Jason
jason345@mail.ru
телефон мобильный
8-909-***-**-**
SBRF
http://sbrf.ru
8-800-555-55-50
Василий
дом
(383) 254-56-89
Мария Степанова
(495) 357-54-12
было бы не плохо если есть сайт у контакта то можно переход по клику, либо клик по мылу для письма
madmasles
29-09-2011, 14:07
rustoss,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)('TrayMenuMode', 1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) WinExists (http://www.autoitscript.com/autoit3/docs/functions/WinExists.htm)(@ScriptName (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptname) & '{[/@$@\]}') Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
AutoItWinSetTitle (http://www.autoitscript.com/autoit3/docs/functions/AutoItWinSetTitle.htm)(@ScriptName (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptname) & '{[/@$@\]}')
$sFile = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\TLF.txt'
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) FileExists (http://www.autoitscript.com/autoit3/docs/functions/FileExists.htm)($sFile) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(16, 'Error', 'No File')
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$sText = FileRead (http://www.autoitscript.com/autoit3/docs/functions/FileRead.htm)($sFile)
$aFIO = StringRegExp (http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm)($sText, '([А-ЯЁA-Z].*?)\h[^А-ЯЁA-Z]', 3)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(16, 'Error', 'StringRegExp')
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$sFIO = ''
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)($aFIO) - 1
$sFIO &= $aFIO[$i] & '|'
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
$aFIO = 0
GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Смотрим Номер телефона', 420, 110)
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('Выберите имя', 10, 10, 186, 17)
$nCombo = GUICtrlCreateCombo (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateCombo.htm)('', 10, 27, 400, 21)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)(-1, $sFIO)
$nGet = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Получить', 340, 55, 70, 23)
$nTLF = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('', 10, 60, 320, 20)
$nLink = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('', 10, 80, 320, 20)
GUICtrlSetFont (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetFont.htm)(-1, 10, 800, 6, "Arial")
GUICtrlSetColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetColor.htm)(-1, 0x0000FF)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
$sFIO = ''
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nCombo, $nGet
$sSearch = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nCombo)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sSearch Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$sTLF = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sText & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@crlf), '(?s).*?' & $sSearch & '.*?[а-яёa-z]?\h+(\(?\d.*?)\r?\n.*', '\1')
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @extended (http://www.autoitscript.com/autoit3/docs/macros.htm#@extended) = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nTLF, StringStripWS (http://www.autoitscript.com/autoit3/docs/functions/StringStripWS.htm)($sTLF, 8))
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) StringRegExp (http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm)($sText, $sSearch & '.*?http://.*?\r?\n') Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$sLink = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sText, '(?s).*?' & $sSearch & '.*?(http://.*?)\h.*', '$1')
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @extended (http://www.autoitscript.com/autoit3/docs/macros.htm#@extended) = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nLink, $sLink)
GUICtrlSetCursor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetCursor.htm)($nLink, 0)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nLink, '')
GUICtrlSetCursor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetCursor.htm)($nLink, -1)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$sLink = ''
$sTLF = ''
$sSearch = ''
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nLink
$sLink = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nLink)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sLink Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
ShellExecute (http://www.autoitscript.com/autoit3/docs/functions/ShellExecute.htm)($sLink)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
$sLink = ''
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Проверял с файлом типа:Jason jason345@mail.ru телефон мобильный 8-909-111-11-11
SBRF http://sbrf.ru 8-800-555-55-50
Василий дом (383) 254-56-89
Мария Степанова 8(495) 357-54-12
Отлично, СПАСИБО! текстовый файл подредактил в строчку все, все работает.
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.