How do I use the new Custom Inventory for Windows String, Math & Date Functions?

Article:HOWTO9182  |  Created: 2005-12-01  |  Updated: 2009-10-28  |  Article URL http://www.symantec.com/docs/HOWTO9182
Article Type
How To


Question
How do I use the new Custom Inventory for Windows String, Math & Date Functions?

Answer

The following string, math, and date functions are available in Custom Inventory for Windows 6.1 SP2 (build 6.1.1075).

Custom inventory source XML sample files for the following functions are available at: https://kb.altiris.com/article.asp?article=4237&p=1.

 

String Manipulation, Math, and Date Functions

Available functions:

  • add 
  • compare
  • comparenocase
  • concat
  • divide
  • find
  • getlength
  • insert
  • left
  • makeupper
  • makelower
  • multiply
  • nsdatetime
  • numcompare
  • remove
  • replace
  • reversefind
  • right
  • substr
  • subtract
  • trim
  • trimright
  • trimleft

Parameters: Following are descriptions of the parameters used in these functions (some are optional depending on the function)
   function: The function to perform.
   str1:       The main source string used in every function.
   str2:       For search type functions, this is the string to search for.
                For comparison type functions, this is the string to compare against str1.
                For math functions, this is the 'number' to add, subtract, multiply, etc.
                Note: str1 & str2 can be previously set variables, e.g., str1='%mystr%'
     
   start:     This is the starting position for substring and find functions. This is zero-based.
   length:  This is the length for substring functions. This is 1-based.

Note: The values for the above parameters are enclosed in single quotes. The entire %STRING function is enclosed in double-quotes.

Note: Functions cannot be embedded one within another. However, multiple functions, one at a time, can be performed on a given string, e.g.:

    <%set mystr='    test string   ' %>
    <%set mystr="%STRING str1=' %mystr%' function='trim' %" %>
    <%set mystr="%STRING str1=%mystr%' function='getlength' %" %>
    ...
   c0="<%writexml "%mystr%"%>"


Examples
:
----------
add: add the numeric version of 2 strings (empty strings considered zero). Can use integers or floating point values.

<%set results="%STRING str1='22' function='add" str2="33' %" %>
results should be '55'
<%set results="%STRING str1='2.7' function='add" str2="3' %" %>
results should be '5.7'

compare: returns the integer indicating equality. Comparison is CASE SENSITIVE
                0=equal
                1=searchstring > src string.
                -1=src string < searchstring  
                -1 also returned on error.

<%set results="%STRING str1='Test String' function='compare" str2="tEst strINg' %" %>
results should be '-1'
<%set results="%STRING str1='Mark' function='compare" str2="Mark' %" %>
results should be '1'
<%set results="%STRING str1='Sam' function='compare" str2="Mark' %" %>
results should be '0'

comparenocase: returns the integer indicating equality. Comparison is CASE INSENSITIVE
                0=equal  
                1=searchstring > src string.
                -1=src string < searchstring  
                -1 also returned on error.

<%set results="%STRING str1='Test String' function='comparenocase" str2="tEst strINg' %" %>
results should be '0'
<%set results="%STRING str1='Mark' function='comparenocase" str2="Sam' %" %>
results should be '-1'
<%set results="%STRING str1='Sam' function='comparenocase" str2="Mark' %" %>
results should be '1'

concat: concatenates 2 strings.

<%set results="%STRING str1='Test ' function='concat" str2="String' %" %>
results should be 'Test String'

divide: divide the numeric version of 2 strings (empty strings considered zero). Can use integers or floating point values.

<%set results="%STRING str1='200' function='divide" str2="10' %" %>
results should be '20'
<%set results="%STRING str1='200' function='divide" str2="15' %" %>
results should be '13.333333'

find: returns the zero-based position of the searchstring found in the original string. If optional starting position is specified, search starts at that position.
      -1 means not found, or error.
      NOTE: FIND IS CASE INSENSITIVE

<%set results="%STRING str1='test string' function='find" str2="str" start="2' %" %>
results should be '5'

getlength: returns the length of the string.

<%set results="%STRING str1='test string' function='getlength' %" %>
results should be 11

insert: inserts a string into the source str1. start is the zero based index position to insert.

<%set results="%STRING str1='test string' function='insert" str2="this " start="5' %" %>
results should be 'test this string'

left: returns the left x characters, or empty string on error.

<%set results="%STRING str1='test string' function='left" length="4' %" %>
results should be 'test'

makeupper: converts the string to all upper case.

<%set results="%STRING str1='test string' function='makeupper' %" %>
results should be 'TEST STRING'

makelower: converts the string to all lower case.

<%set results="%STRING str1='Test STRING' function='makelower' %" %>
results should be 'test string'

multiply: multiply the numeric version of 2 strings (empty strings considered zero).
     can use integers or floating point values.

<%set results="%STRING str1='2' function='multiply" str2="10' %" %>
results should be '20'
<%set results="%STRING str1='-10' function='multiply" str2="30' %" %>
results should be '-300'
<%set results="%STRING str1='20.5' function='multiply" str2="-3.25' %" %>
results should be '-66.625'

nsdatetime: converts a string date to NS datetime format (YYYY-MM-DDTHH:MM:SS). Function will determine format of input string

<%set results="%STRING str1='10/21/2004 12:45:05' function='nsdatetime' %" %>
results should be '2004-10-21T12:45:05'
<%set results="%STRING str1='10-21-2004 12:45:05' function='nsdatetime' %" %>
results should be '2004-10-21T12:45:05'
<%set results="%STRING str1='10-21-2004' function='nsdatetime' %" %>
results should be '2004-10-21T00:00:00'
<%set results="%STRING str1='2004/10/21' function='nsdatetime' %" %>
results should be '2004-10-21T00:00:00'

numcompare: numerically compare the numeric version of 2 strings (empty strings considered zero).
     can use integers or floating point values.

<%set results="%STRING str1='22' function='numcompare" str2="22' %" %>
results should be '0'
<%set results="%STRING str1='10' function='numcompare" str2="30' %" %>
results should be '-1'
<%set results="%STRING str1='20' function='numcompare" str2="-5' %" %>
results should be '1'

remove: removes all occurrences of a character from a string.

<%set results="%STRING str1='test string' function='remove" str2="s' %" %>
results should be 'Tet tring'

replace: replaces all occurrences in str1 of str2 with str3 

<%set results="%STRING str1='test this string' function='replace" str2="this" str3="that' %" %>
results should be 'test that string'

reversefind: returns the zero-based position of the searchstring found in the original string.
      -1 means not found, or error.
      only first character from searchstring is used.

<%set results="%STRING str1='test string' function='reversefind" str2="s' %" %>
results should be '5'

right: returns the right x characters, or empty string on error.

<%set results="%STRING str1='test string' function='right" length="5' %" %>
results should be 'tring'

substr: returns a subset string from the original string starting in required position x for optional length y
        returns empty string on error.

<%set results="%STRING str1='test string' function='substr" start="2" length="5' %" %>
results should be 'st st'

substr: returns a subset string from the original string starting in required position x. Since no length specified, returns the remaining portion of the string. Returns empty string on error.

<%set results="%STRING str1='test string' function='substr" start="2' %" %>
results should be 'st string'

subtract: subtract the numeric version of 2 strings (empty strings considered zero). Can use integers or floating point values.

<%set results="%STRING str1='30' function='subtract" str2="10' %" %>
results should be '20'
<%set results="%STRING str1='10' function='subtract" str2="30' %" %>
results should be '-20'
<%set results="%STRING str1='20.5' function='subtract" str2="10' %" %>
results should be '10.5'
<%set results="%STRING str1='10.5' function='subtract" str2="8.5' %" %>
results should be '2'

trim: no parameters.

<%set results="%STRING str1='   test string   ' function='trim' %" %>
results should be 'test string'

trimright: no parameters.

<%set results="%STRING str1='   test string   ' function='trimright' %" %>
results should be '   test string'

trimright: specifying characters to trim in the searchstring parameters.

<%set results="%STRING str1='test string' function='trimright" str2="ing' %" %>
results should be 'test str'

trimleft: no parameters.

<%set results="%STRING str1='   test string   ' function='trimleft' %" %>
results should be 'test string   '

trimleft: specifying characters to trim in the searchstring parameters.

<%set results="%STRING str1='test string' function='trimleft" str2="te' %" %>
results should be 'st string'



Legacy ID



4265


Article URL http://www.symantec.com/docs/HOWTO9182


Terms of use for this information are found in Legal Notices