I would like to retrieve a section name from an INI file with only a unique key name
My ini file :
...
[Area.104]
Title=Central North America
Local=Scenery\NAMC
Layer=104
Active=TRUE
Required=FALSE
[Area.105]
Title=Eastern North America
Local=Scenery\NAME
Layer=105
Active=TRUE
Required=FALSE
[Area.106]
Title=Western North America
Local=Scenery\NAMW
Layer=106
Active=TRUE
Required=FALSE
...
How can I get section name [Area.105] from unique key Title=Eastern North America ???
Thank you
I have two ways of finding the required Area code:
METHOD 1
METHOD 2(Using Regular Expression)
>>>Click here for Regex Demo<<<
Regex Explanation:
\[
- matches literal[
([^]]+)
- capture 1+ occurrence of any character which is not]
in a group]
- matches literal]
\s*
- matches 0+ white-spaces(which include the newline characters)Title=
- matches the textTitle=
. This is then concatenated with the variablestrKey
containing the value of unique title.