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

Strings

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

add a value to a pre-existing list only if it is not already there

Keywords: 	 check for dupes  string duplicates

Question:

I have the following script that I use for updating proxy server exceptions. This script runs in our logon script, and as you see in the script I read in the current values, as some programmers have custom settings that I don't want to overwrite. How can I parse out any duplicates and only have the value show up once in the list instead of growing every time that they login.
RegSetValue(@REGCURRENT,'Software\Microsoft\Windows\CurrentVersion\Internet Settings[ProxyServer]','PROXY:80')
RegSetDword(@REGCURRENT,'Software\Microsoft\Windows\CurrentVersion\Internet Settings[ProxyEnable]','1')

regkey = RegOpenKey(@REGCURRENT, "Software\Microsoft\Windows\CurrentVersion\Internet Settings")
curproxyvalue = RegQueryValue(regkey, "[ProxyOverride]")


ProxyValue = '127.0.0.1;*.dairylandagents.com;*.dairyland-direct.com;*.parkerservicesonline.com;*.sentry-direct.com;*.sentryins.com;*.sentryonline.com*.sentry.com;*.life-insurance.com;*.middlesexinsurance.com;'
ProxyValue2 = '*.middlesex-insurance.com;*.patriotgeneral.com;*.patriot-general.com;*.sentry-fund.com;*.sentry-ins.com;*.sentryinsurance.com;*.sentry-insurance.com;*.slonyinsurance.com;*.slony-insurance.com;'
ProxyValue = Strcat(CurProxyValue,proxyvalue,proxyvalue2)
RegSetValue(@REGCURRENT,'Software\Microsoft\Windows\CurrentVersion\Internet Settings[ProxyOverride]',ProxyValue)
RegSetValue(@REGCURRENT,'Software\Microsoft\Ftp[Use Web Based FTP]','NO')
RegSetValue(@REGCURRENT,'Software\Microsoft\Ftp[Use PASV]','YES') 

Answer:

So you want to add a value to a pre-existing list only if it is not already there.
preexisting='*.this;*.that;*.other;*.something;*.Else;*.CatANDdog;*.otter'
wanttoadd='*.catanddog'

;decide if it is in the list or not.
;Put semicolons on both ends.
testlist=strcat(";",preexisting,";")
;put semicolons on both sides of wanttoadd
testadd=strcat(";",wanttoadd,";")

;see if testadd exists in testlist
if strindexNC(testlist,testadd,0,@fwdscan)==0
  ; ==0 does not exist.  Add
  newlist=strcat(preexisting,";",wanttoadd)
else
  ;its already there
  newlist=preexisting
endif
Message("NewList",newlist)

Article ID:   W15300
File Created: 2002:09:05:13:51:12
Last Updated: 2002:09:05:13:51:12