Jump to content

Recommended Posts

Hi all,

I'm really stuck on array search. Please refer the attach for array display. It select LSD_6_INCH_ENG but correct 

string is LSD_6_INCH. Please advise to solve this issues.

$Search = _ArraySearch($aRecords, $Recipe,0,$count,0,1,3,0)

 

ScreenHunter_03 Apr. 09 15.32.gif

Share this post


Link to post
Share on other sites

@Rammanan
It's difficult to say without seeing the content of $Recipe variable :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

@Rammanan

Global $arrArray[12] = [12, _
                        "ENGINEERING_REWORK_FBAR", _
                        "LSD_6_INCH_ENG", _
                        "LSD_8_INCH_ENG", _
                        "CHOOI-Humming", _
                        "ENGINEERING_BUYOFF_6_INCH", _
                        "1213", _
                        "MOLOKAI_LSD_13_MIL", _
                        "LSD_6_INCH", _
                        "FBAR_6_INCH", _
                        "LSD_IDT_10MIL", _
                        "LSD_8_INCH"], _
       $strSearch = "LSD_6_INCH", _
       $intIndex = -1

$intIndex = _ArraySearch($arrArray, $strSearch)
If @error Then
    ConsoleWrite("_ArraySearch() ERR: " & @error & @CRLF)
Else
    ConsoleWrite("Index: " & $intIndex & @CRLF)
EndIf

:)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
2 hours ago, Rammanan said:

@FrancescoDiMuro

Need hard code the string to search. Problem is array display not same to all machine.

No, Francesco was giving you an example.  The problem is that YOUR _ArraySearch is badly formatted.  Please refer to Help File, to understand each parameter.  Look especially at the sixth parameter...

Share this post


Link to post
Share on other sites
Local $Recipe = "LSD_6_INCH"

     Dim $aRecords
        If Not _FileReadToArray("C:\temp\recipe.txt",$aRecords) Then ;(Read txt file at local c)
           ;MsgBox(4096,"Error", " Error reading log to Array   error:" & @error)
           ConsoleWrite("Error: Script cannot find C:\temp\recipe.txt file")
           Local $1open = FileOpen("C:\Temp\error.txt",1)
           Local $write = FileWrite($1open,"Error: Script cannot find C:\temp\recipe.txt file to read recipe")
           FileClose($1open)
           FileDelete("C:\Temp\recipe.txt")
           Exit
        EndIf

         _ArrayDisplay($aRecords, "Entries left in the array")
        _ArrayPop($aRecords)        ;(Delete last entry at array)
         $aArray = _ArrayDisplay($aRecords, "Entries left in the array")
        $Search = _ArraySearch($aRecords, $Recipe,0,0,0,2)
        MsgBox(32,'',$Search)

Return get -1

 

Share this post


Link to post
Share on other sites

Try a partial search, if this returns the correct index item, then as Nine mentioned there is probably a hidden character.

$Search = _ArraySearch($aRecords, $Recipe,0,0,0,1)

 

Share this post


Link to post
Share on other sites
1 hour ago, Rammanan said:

recipe.txt file look like this. No space 

You should take a look with Notepad++, or any other text editor which let you see special characters like spaces, new line, and so on :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

Is it the same behavior on the LSD_8_INCH lines?  Or is this behvaior unique to the 6 inchers?

Those are just some of the myriad questions that abound until the source file is produced.

***to end speculation you could just run a stringstripws for leading and trailing (and maybe just trailing..)  as we would see all others in the notepad screenshot.  Unless yall know cool ways to hide shit in the middle of a string in notepad, which you need to show me.

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
1 minute ago, iamtheky said:

Unless yall know cool ways to hide shit in the middle of a string in notepad, which you need to show me.

Sick :muttley:


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

@Rammanan

9 minutes ago, Rammanan said:

I check using notepad++ but no space show

image.png.6234722bbb42ac72ce997ac225f76c19.png
Each line in the file contains spaces, so, you should do something like this:

#include <Array.au3>
#include <StringConstants.au3>

Global $arrArray, _
       $strSearch = "LSD_6_INCH", _
       $intIndex = -1

_FileReadToArray(@ScriptDir & "\recipe.txt", $arrArray)
If @error Then Exit ConsoleWrite("_FileReadToArray() ERR: " & @error & @CRLF)

$arrArray = StringRegExp(StringStripWS(_ArrayToString($arrArray), $STR_STRIPALL), '([^|]+)', $STR_REGEXPARRAYGLOBALMATCH)

$intIndex = _ArraySearch($arrArray, $strSearch)
If @error Then
    ConsoleWrite("_ArraySearch() ERR: " & @error & @CRLF)
Else
    ConsoleWrite("Index: " & $intIndex & @CRLF)
EndIf

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...