LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ini_PutString puts extra space quotes around the string

Hi, I am trying to use CVI's Ini_PutString function to modify an existing ini file that looks like this:
 
[GENERAL]
UNIT=64AD34F
 
so I have Ini_GetStringCopy(pFile, "GENERAL", "UNIT", &Value);
 
and I was able to get 64AD34F,
 
then I want to write back to the ini file using Ini_PutString(pFile, "GENERAL", "UNIT", &Value);
 
now my ini file looks like this:
 
[GENERAL]
UNIT = "64AD34F"
 
now my file is littered with all these " that are not desired, plus CVI puts extra spaces before and after =.  Is there anyway for me to work around this?  Any help would be greatly appreciated.
0 Kudos
Message 1 of 9
(4,700 Views)

As far as I know there is no way of excluding quotes and spaces using the inifile instrument unless you decide to modify the instrument itself (which is distributed with source so that can be customized in case of need).

Some years ago I succesfully modified this instrument adding two extra function panels for Ini_Put and Ini_Get functions which (if I remember well: it happened wth rel. 5 or 5.5 of the language Smiley Surprised ) take a flag as an input for "Has quotes" parameter. You may want do follow this way in case this item is strategic for you.

To modify the instrument, select the inifile instrument in the list of instruments and execute "Attach and edit source" function to see the source code for the instrument.

 

Despite my trial, I finally decided to abandon these modifications mainly for not having to check and modify each version of the instrument after every patch or new release of CVI. But this is a personal attitude and you may feel this is not a severe handicap with respect to what you gain following the customization way.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,688 Views)
I had time to look into inifile instrument and can confirm you that the Ini_Put function is the one in charge of creating the value item associated with a particualr item in a section and takes a boolean for the last parameter "addMarkerQuotes". Ini_Put is the function eventually called by all the Ini_PutXXX functions so you may want either to create a function panel for this function or to create a new Ini_WriteStringEx adding the addMarkerQuotes parameter. Inside the code there is a warning to always add quotes for multiline item values which in my opinion is to be considered since a multiline string is truncated at fixed lenght by the function so it may happen that some of the lines terminate with a space which would be ignored without the quotes.
 
As per the extra spaces sorrounding the equal sign, to eliminate them you must modify the nameValueOutputSeparatorToken which by default is " = ". I suppose it is so mainly for aestethic reasons so you can safely shorten it.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 9
(4,665 Views)

 

Hi Roberto,

I ran in to this very same issue where I don't want spaces surrounding equal sign. After creating this ini file I am passing it to a dll but this third part dll doesn't work with extra spaces. I looked at ini file spec and there is no set standard for spaces surrounding equal sign.

 

I looked in to Ini_SetTokens and default value separator is without spaces. "="

So where are these extra spaces coming from when I write to ini file and how to remove them?

 

I tried following function but it doesn't work.

Ini_SetTokens (handle, '[', ']', "=", ";");

 

Help says:

This function specifies the tokens used as delimiters in the text representation of the sections headings and tag/value pairs.

If you do not call this function, the default tokens are:

Section Name Start Character "["
Section Name End Character "]"
Value Separator "="
Comment Marker ";"

 

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 4 of 9
(4,177 Views)

The item separator is defined in Ini_SetTokens, specifically in this line:

        sprintf(iniText->nameValueOutputSeparatorToken, " %s ", iniText->nameValueInputSeparatorToken);
 

You may want to modifiy this line to put extra spaces away. Remember to either rename the inifile instrument or to keep a copy of the modified source, since some CVI update could modify this instrument without notice.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 9
(4,163 Views)

Thanks for your quick response Roberto. It is working as expected.

To me, this looks like like a bug.

Ini_SetTokens function in inifile.c adds this spaces which doesn't make sense since there is valueSeparator argument to this function.

Anyways, I have modified my copy for now.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 6 of 9
(4,159 Views)

I realize this thread is very old but I just thought I'd post something and hopefully save somebody some headaches.

From my experience working with CVI2015 the inifile.fp function panel always puts spaces on either side of the equals sign and also puts quotation marks around strings.  These formats are incompatible with the software whos ini file I'm modifying.  But I was able to write some C code that creates a powershell command line to locate and replace strings in a text file.  here is how I call it and how the function looks.  But to use it you need to have a way of sending commands to powershell from your Labwindows code.  Let me know if you need that.

 

 

 

 

0 Kudos
Message 7 of 9
(3,283 Views)

It may be worth noting that starting from CVI2012 Ini_SetAddQuotesToStrings function has been added to IniFile instrument: as the help recitates

Specifying 0 or selecting No in the Add Quotes To Strings parameter of this function panel modifies the behavior of the Ini_Text so that Ini_WriteToFile and Ini_WriteGeneric write string values without the surrounding double quotation marks. This can be useful when writing .ini files that are read by applications that do not expect double quotation marks around string values.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 8 of 9
(3,275 Views)

Thanks Roberto for your tip!  It's good you added it because the method I included in my attachment to my previous post for fixing this issue actually did not work.  So I've modified a few lines to use Ini_SetAddQuotesToStrings() as you suggest which takes care of the same problem.  This function returns the previous state of the "AddQuotesToStrings" parameter which by default is 1 so keep that in mind if you are tracking errors. 

0 Kudos
Message 9 of 9
(3,254 Views)