Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Read .ini backwards


  • Please log in to reply
No replies to this topic
Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
There is an inbuilt function in AHK to read ini file values when Section and Key are given. I've faced a couple of times when I needed the opposite, I had the value and had to know the Section and Key.

This little function gives the following:
section of the value
Key of the value
line no. in .ini file

ToFind=SomeValue
IniFile=Inifile.ini

Loop, Read, %IniFile%
{
        IfInString, A_LoopReadLine,[
        IfInString, A_LoopReadLine,]
        SetEnv, Section, %A_LoopReadLine%
        
        StringGetPos, EqPos, A_LoopReadLine, =
        StringTrimLeft, Value, A_LoopReadLine, %EqPos%
        IfInString, Value, %tofind%
        {
                StringLeft, Found, A_LoopReadLine, %EqPos%
                
                ;Available info:
                ;%Section% = section of the value
                ;%ToFind% = value to be found
                ;%Found% = Key of the value
                ;%a_index% = line no. in .ini file
                
                Msgbox,0,Found, %Section%`n`n%Found%=%ToFind%`n`n(Line %a_index%)
        }        
}

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat