如何删除INI中的某个键值-ZZ

    From: xuyibo.org  Date: 2021-06-26 09:48 PM

    > There is no API call for deleting an INI entry.
    Oh yes there is, and it’s WritePrivateProfileString.
    lpKeyName
    [in] Pointer to a null-terminated string containing the key to be associated
    with the string. If the key does not exist in the specified section, it is
    created. If this parameter is NULL, the entire section, including all
    entries in the section, is deleted.

    lpString
    [in] Pointer to a null-terminated string to be written to the file. If this
    parameter is NULL, the key pointed to by the lpKeyName parameter is deleted.

    > You can use WritePrivateProfileSection to ‘replace’ keys in sections.
    Right. So, if you want to keep the name of the section for whatever reason,
    just replace all keys in the section with nothing (IOW, a 0-length string or
    vbNullString as Juergen showed). Granted, you’re not really deleting the
    section, but you are deleting all entries within the section. If you want
    the entire section, including the section name, gone, then use
    WritePrivateProfileString.

    INI:
    [Tst]
    i=1

    [UPDATE]
    DateTime=2008/06/10

    Code:
    WritePrivateProfileString(‘UPDATE’, NULL, ‘d:\\tst.ini’):

    Result:
    [Tst]
    i=1

    The whole UPDATE section include section name is deleted.

    EMail: * 如果为有效的邮箱地址,将自动发送站长回复

网站地图