Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:32:34+00:00 2026-06-15T01:32:34+00:00

Being that this application has evolved over the years, there are still some INI

  • 0

Being that this application has evolved over the years, there are still some INI files. I have a class that reads entries using GetPrivateProfileString.

At the top of the class we see this:

    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section,
        string key, string def, StringBuilder retVal,
        int size, string filePath);

And it looks like there is a public method that looks something like this:

    public string IniReadValue(string Section, string Key)
    {
        // If string greater than 254 characters (255th spot is null-terminator),
        // string will be truncated.
        const int capacity = 255;
        StringBuilder temp = new StringBuilder(capacity);
        int i = GetPrivateProfileString(Section, Key, "", temp,
                                        capacity, this.m_Path);
        return temp.ToString();
    }

I recently noticed that GetPrivateProfileString trims it’s data. Therefore, if my INI file has an entry like this:

SomeData= Notice the three trailing spaces at front and back of this sentence.

It will retrieve it like (notice that it’s trimmed to the left and right – ignore quotes):

“Notice the three trailing spaces at front and back of this sentence.”

I don’t want it to Trim. Is that out of my control? INI files aren’t allowed to have spaces after the equal sign (e.g. SomeData=)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:32:35+00:00Added an answer on June 15, 2026 at 1:32 am

    As pointed out in the comments, that is how the API works. If you can live with that, you can at least save some DllImport work by using for example this library/wrapper (includes source, just one file):

    IniReader

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a application with a screen manager class that is causing me some
There is a post here that talks about this as being a bad idea
this is a simple question. I have a form that is being validated using
I have this running software that is currently being used by about 400 people.
I have written an application for Android. the main part being that it communicates
We have an application that has two types of users. Depending on how the
I have a closed-source Linux application that I want to distribute. This application is
I have a large 1 page ASP.Net application. Much of this application has been
I am working on an application that involves some gis stuff. There would be
In code: //I know that to get this effect (being able to use it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.