WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Read quote in ini file.

Keywords:  Read quotes ini file inireadpvt

Question:

I am having difficulty with IniReadPvt(...) reading embedded quotes and spaces in an ini file.

For example my ini file reads as follows....
[MAIN]
keyword=" hello "

I want to read " hello " from the file, but it seems to be removing the quotes and the spaces....

Any ideas?

Answer:

Ok, here is the issue. The iniReadPvt is going to recognize the quotes. Quotes are ignored by ini file operations. But it does *see* the spaces.

Depending on your needs
------------------------
You could try this.....

dastring=IniReadPvt (section, keyname, default, filename)
message("Length of string (Notice it does see the
spaces)",strlen(dastring))
;concatenate quotes onto the string
dastring=strcat('"',dastring,'"')
message("resulting string",dastring)
exit

*OR*

You could use a character in the ini file to stand in place of quotes, then convert them to quotes once read into winbatch....

NOTE: The character you use in the ini file cannot possibly match any other character in the ini file....

INI file

[MAIN]
Keyword=#$   item   #$

WBT file

dastring=IniReadPvt (section, keyname, default, filename)
;Replace #$ with "
dastring=StrReplace(dastring, '#$', '"')
message("resulting string",dastring)
exit

*OR*

Here's a little IniReadPvt replacement UDF a user wrote that allows for quotes.

#DefineFunction IniReadPvtQ(Section,KeyName,DefVal,IniFile)
Buffer = FileGet(IniFile)
RetVal = DefVal
i = 0
Section = StrCat('[',Section,']')
i = StrIndexNC(Buffer,Section,i,@FwdScan)
If i==0 Then Return RetVal
i = i + StrLen(Section)
NextSection = StrIndex(Buffer,"[",i,@FwdScan)
While @True
	i = StrIndexNC(Buffer,StrCat(@CrLf,KeyName),i,@FwdScan)
	If i==0 Then Break
	i = i + 2
	a = StrSub(Buffer,i+StrLen(KeyName),1)
	If a==@Tab || a==' ' || a=='=' Then Break
EndWhile
If i==0 || (i>NextSection && NextSection<>0) Then Return RetVal
i = i + StrLen(KeyName)
i = StrIndex(Buffer,"=",i,@FwdScan)
e = StrIndex(Buffer,@CrLf,i,@FwdScan)
If e==0 Then e = StrLen(Buffer)+1
RetVal = StrSub(Buffer,i+1,e-i-1)
Drop(Buffer)
Return RetVal
#EndFunction


Article ID:   W14610
Filename:   Read quote in ini file.txt
File Created: 2005:05:02:08:35:10
Last Updated: 2005:05:02:08:35:10