Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    965
    Thanks
    3
    Thanked 12 Times in 11 Posts

    Desktop.ini / GetPrivateProfileString

    In folders that are created by one of our vendors, there is a desktop.ini that is more complex than the standard INI file that can be written/read with VBA System.PrivateProfileString. The value of the key has more than 255 characters, so I use the Windows API GetPrivateProfileString to read the value of key "elements", as shown below. (I have forced the line to wrap for this post.)

    I want to get the value of "database". I have success reading the full value of key "elements" and then parsing the string to get "US001". I'm wondering if there is a more direct way to get the value of "database" without parsing.

    Does anyone know if this is possibe?
    Thank you.

    [dms.elements]
    elements={"workspace_profile":{"author":"ADMIN","c lass":"DOC","create_date":"2017-06-09T21:30:15.000Z","database":"US001",
    "default_security":"public","doc_number":"11343807 ","edit_date":"2017-06-09T21:30:15.000Z",
    "operator":"ADMIN","owner":"ADMIN"}}

  2. #2
    Administrator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    3,344
    Thanks
    151
    Thanked 900 Times in 726 Posts
    Yes, it should be possible using a regular expression to do string searching because "database" appears be unique in the example you've shown.

    Unfortunately I have zero experience in using RegEx in VBA (and very little in AHK where I've used it to identify MAC addresses and GUIDs in gobs [technical term ] of text).

    For example, here's a one-liner in AHK to identify the pattern I want:

    Code:
    Text =
    (
    Here is some random text leading to the
    the text I want 23f6-a08c-0000-32ff-0290 which
    just appeared
    ) 
    
    RegExMatch(Text, "(.{4}-){4}.{4}", Match) ; This is the AHK one-liner that does the business... all the rest is fluff
    MsgBox, % Match
    Result:
    RegExMatch_result.png

    Have a look at VBA RegEx: How to Evaluate and Use “Regular Expressions”.

    Hope this helps...
    Last edited by Rick Corbett; 2018-05-03 at 18:39.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    965
    Thanks
    3
    Thanked 12 Times in 11 Posts
    Thanks very much. It's helpful to know about this VBScript add-in. I can get the results I need with InStr and Mid statements. I've written a function that requires only 3 lines of code. I'll stick with that as it's easy for others to read who might not be familiar with RegEx. I'm grateful for your response.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •