|Home » KB » 如何删除INI中的某个键值-ZZ|
> There is no API call for deleting an INI entry.
Oh yes there is, and it’s WritePrivateProfileString.
[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.
[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(‘UPDATE’, NULL, ‘d:\\tst.ini’):
The whole UPDATE section include section name is deleted.
|Copyright © 2009 xuyibo.org All right reserved.|