autohotkey - AHK Grepping an Array from Text File -


i wrote ahk script prompts user input through inputbox, navigates through text file based on user input line line , copy output clipboard.

example:

  • if "4max" given userinput, should copy output "sleep" clipboard.

  • if "3ben" given userinput, should copy output "jog" clipboard.

sample text file :

max:eat:drink:sleep:play jerry:eat:play:drink:jog laura:drink:eat:sleep:play ben:sleep:jog:eat:drink 

can please enhance below script?

also when run script blank notepad open, pasting current item in clipboard notepad. :(.

script:

#singleinstance, force #include c:\users\mpechett\desktop\ahk\tf.ahk  inputbox, searchtext, search name  x = %searchtext% regexmatch(x, "(\d*)(\w*)", y) searchtext:= % y2 ptext = % tf_find("c:\users\mpechett\desktop\ahk\test.txt", "","", searchtext, 1, 1) stringsplit, word_array, ptext, :, .  ;msgbox % word_array%y1%  clipboard = % word_array%y1% msgbox, %clipboard%  esc::exitapp 

okay, didn't implement design. looks clipboard assignment using deprecated = sign vs := standard assigning objects, may have been issue. didn't test code, decided better rewrite entire solution, without using outside library.

try:

    testdata =     (     max:eat:drink:sleep:play     jerry:eat:play:drink:jog     laura:drink:eat:sleep:play     ben:sleep:jog:eat:drink     )      inputbox, searchtext, search name      msgbox % clipboard := grepfile(searchtext, testdata)      grepfile(userinput, file) {         e, v in strsplit(userinput) {             if v alpha                 key .= v             else                  num .= v         }          arr := formatfile(file)          return arr[key][num]     }      formatfile(file) {         ourobj := {}         e, line in strsplit(file, "`n", "`r") {             arr := strsplit(line, ":")             ourobj[(arr.1)] := arr                      }         return ourobj     }  

edit:

testdata = ( max-test:eat:drink:sleep:play jerry-test:eat:play:drink:jog laura-test:drink:eat:sleep:play ben-test:sleep:jog:eat:drink )  testdata := strreplace(testdata, "-test")  inputbox, searchtext, search name  msgbox % clipboard := grepfile(searchtext, testdata)  grepfile(userinput, file) {     e, v in strsplit(userinput) {         if v alpha             key .= v         else              num .= v     }      arr := formatfile(file)      return arr[key][num] }  formatfile(file) {     ourobj := {}     e, line in strsplit(file, "`n", "`r") {         arr := strsplit(line, ":")         ourobj[(arr.1)] := arr                  }     return ourobj } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -