Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Read Text File based on a key

$
0
0

So I have a text file that contain:

 

key1=value1

key2=value2

key3=value3

 

I want to create a function that return value for key I'm searching for.

 

I'm not really need this because I already have my code working great, but I wonder and keen to learning another ways to do it :)

I believe there must be a dozen ways to do this with less lines of codes and in higher processing speed compared to my stupid and simple code.

 

Func ReadTextFileBaseOnKey($fFile, $sKey)     $iLine = 1     $sResult = ""     $file = fileOPen($fFile, 0)     while 1         $sRead2 = FileReadLine($file, $iLine)         if @error Then             FileClose($file)             ExitLoop         Else             $sRead = FileReadLine($fFile, $iLine)             If StringLeft($sRead, StringLen($sKey)) = $sKey then                 $sResult = StringRight($sRead, StringLen($sRead)-StringInStr($sRead,"=",0))                 ExitLoop             EndIf             $iLine = $iLine + 1         EndIf     WEnd     FileClose($file)     Return $sResult EndFunc

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>