Jump to content



Photo

have a problem with a search code gave me here


  • This topic is locked This topic is locked
8 replies to this topic

#1 gil900

gil900

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 17 August 2012 - 04:06 PM

Hello,
Melba23 gave me here:
http://www.autoitscript.com/forum/topic/143266-need-help-with-my-first-algorithm/

This search code:

#include <File.au3> ; Read the file into an array Global $aLines _FileReadToArray("test.txt", $aLines) ; Loop through the array looking for "$" For $i = 1 To $aLines[0] If StringInStr($aLines[$i], "$") Then MsgBox(4096, "", "Found $ at line: " & $i) Else MsgBox(4096, "", "Not in: " & $i) EndIf Next


Excellent code .. I'm still trying to learn it.

But it fails in this case:

test1 test2 te st3 test4


If I try to search for the test1 / test2 / test4
So it works well.

but not if i try to search for test3 .

I understand why it does not work.
But in my case I have to make it work.


Thanks for helpers!

Edited by gil900, 17 August 2012 - 04:08 PM.








#2 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,383 posts

Posted 17 August 2012 - 04:15 PM

gil900,

It is hardly surprising that the code I gave you in the other thread does not work for "test3" as it is split over a line-break! ;)

Before I start thinking of how we might meet your new requirements, which line number do you want returned for values like test3 that exist on 2 lines - 1 or 2? :huh:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#3 gil900

gil900

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 17 August 2012 - 04:23 PM

Clear why it does not work.
But this idea - it has to deal with line-break.

I did not understand what you are asking me ..
I just need it to deal with line-break

This is my only requirement.
With the other things I'll deal (I think).
It's just the part I do not know how to do ..

#4 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,383 posts

Posted 17 August 2012 - 04:31 PM

gil900,

Try this:
AutoIt         
#include <File.au3> ; Read the file into an array Global $aLines _FileReadToArray("test.txt", $aLines) ; And into a variable $sFile_Text = FileRead("test.txt") ; Remove all @CR and @LF $sFile_Text = StringRegExpReplace($sFile_Text, "[rn]", "") ConsoleWrite($sFile_Text & @CRLF) While 1     $sSearch_String = InputBox("Input search string", "Leave empty to exit")     If $sSearch_String = "" Then         ExitLoop     EndIf     ; Loop through the array looking for search string     $fFound = False     For $i = 1 To $aLines[0]         If StringInStr($aLines[$i], $sSearch_String) Then             $fFound = True             MsgBox(4096, "", "Found " & $sSearch_String & " at line: " & $i)         EndIf     Next     ; If not found then we look for the string in the whole file text     If Not $fFound Then         $iLocation = StringInStr($sFile_Text, $sSearch_String)         ; If it is found then work out the line         If $iLocation Then             $iCharCount = 0             For $i = 1 To $aLines[0]                 $iCharCount += StringLen($aLines[$i])                 If $iCharCount > $iLocation Then                     MsgBox(4096, "", "Found " & $sSearch_String & " at line (split): " & $i)                     ExitLoop                 EndIf             Next         EndIf     EndIf WEnd

All clear? :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#5 gil900

gil900

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 17 August 2012 - 04:36 PM

gil900,

Try this:

AutoIt         
#include <File.au3> ; Read the file into an array Global $aLines _FileReadToArray("test.txt", $aLines) ; And into a variable $sFile_Text = FileRead("test.txt") ; Remove all @CR and @LF $sFile_Text = StringRegExpReplace($sFile_Text, "[rn]", "") ConsoleWrite($sFile_Text & @CRLF) While 1 $sSearch_String = InputBox("Input search string", "Leave empty to exit") If $sSearch_String = "" Then ExitLoop EndIf ; Loop through the array looking for search string $fFound = False For $i = 1 To $aLines[0] If StringInStr($aLines[$i], $sSearch_String) Then $fFound = True MsgBox(4096, "", "Found " & $sSearch_String & " at line: " & $i) EndIf Next ; If not found then we look for the string in the whole file text If Not $fFound Then $iLocation = StringInStr($sFile_Text, $sSearch_String) ; If it is found then work out the line If $iLocation Then $iCharCount = 0 For $i = 1 To $aLines[0] $iCharCount += StringLen($aLines[$i]) If $iCharCount > $iLocation Then MsgBox(4096, "", "Found " & $sSearch_String & " at line (split): " & $i) ExitLoop EndIf Next EndIf EndIf WEnd
All clear? :)

M23

Seems unclear.
But I'll try to figure it out.

Thank you!
I check it

#6 gil900

gil900

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 17 August 2012 - 04:41 PM

It works!
Thank you!

#7 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,383 posts

Posted 17 August 2012 - 04:42 PM

gil900,

Seems unclear.
But I'll try to figure it out

Just ask if you need any more help. :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#8 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,383 posts

Posted 17 August 2012 - 04:55 PM

gil900,

If the text is in memory does it still have the line breaks? How is the text generated? What exactly are you trying to do? :huh:

A little more information would be useful - I hate producing example after example because the OP does not explain the problem in enough detail at first. ;)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#9 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,383 posts

Posted 18 August 2012 - 09:30 PM

gil900,

And you think I am going to help with a script searching for "teencore Hustler Videosz"? :huh:

Not a chance - and do not try opening another thread with a different set of search words either. :naughty:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users