Windows API: GetProfileString and GetPrivateProfileString clears quotes
Question by Guest | 2012-11-26 at 06:25
I am using the Windows API functions GetPrivateProfileString, GetProfilString, WritePrivateProfileString and WriteProfilString to store strings in an INI file.
However, often, it comes to the problem that single and also double quotes disappear and can not be read correctly, although the strings are correctly stored in the INI file and can be looked up there with all quotation marks properly.
On a forum, I read that the quotes must be doubled to make it work. But if I do this, another strange behaviour occurs: while for some quotes the problem is solved, the other quotes that have been retrieved correctly before, are read out two times, which is of course not desirable. Is there a solution?
Related Topics
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
Lazarus: Detect Operating System (Compiler Switch)
Tutorial | 0 Comments
Put Windows via Script into Hibernation or Sleep Mode
Tutorial | 0 Comments
Android SDK Manager not showing new API Versions
Question | 1 Answer
Android SDK Manager: Problem with installing packages "File not Found (Access is denied) Done. Nothing was installed"
Question | 4 Answers
Change Minimum API Level of Android Studio Project
Question | 1 Answer
Delphi: System-Wide HotKey
Tutorial | 1 Comment
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
If a string is enclosed with single or double quotes in an INI file, GetProfileString returns the string unquoted.
Example:
Although in the INI file, the variants in key1, key2 and key3 are differing and notated with and without quotation marks, GetProfileString delivers the same result for each line. The situation is different in the examples key4 to key8 where the quotes are not enclosing the string.
The Solution
Before writing the string with WriteProfileString, check whether the string has quotation marks of the same type at its front and back. If so, double these quotes while remaining the others, otherwise, leave the string unchanged.
2012-11-27 at 14:13