Jump to content

have a problem with a search code gave me here


Guest
 Share

Recommended Posts

Hello,

Melba23 gave me here:

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 Guest
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

  • Moderators

gil900,

Try this:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

gil900,

Try this:

#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

Link to comment
Share on other sites

  • Moderators

gil900,

Seems unclear.

But I'll try to figure it out

Just ask if you need any more help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...