Client Management Suite

 View Only

Using Custom Inventory's String, Math & Date Functions 

Aug 24, 2007 11:07 AM

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: ftp://ftp2.altiris.com/files/CustomInvSamples/wininv/stringfunctions/

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
  • trimright
  • trimleft
  • trim

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.
  • 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: str1 & str2 can be previously set variables, e.g., str1='%mystr%'
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:

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'

getlength: returns the length of the string. <%set results="%STRING str1='test string' function='getlength' %" %> results should be 11

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'

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'

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'

find: returns the zero-based position of the searchstring found in the original string. if optional starting position specified, starts search 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'

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'

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'

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'

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'

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'

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'

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'

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'

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'

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'

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'

Complete Custom Inventory Source Samples:

Find String (find) Source XML:

<?xml version="1.0" encoding="windows-1252"?>
<InventoryClasses>

<InventoryClass name="string_find" manufacturer='Altiris' description='' platform='Win32' version='1.0' mifClass='Altiris|DSServerIP|1.0'> 
  <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> 
    <s:Schema id="RowsetSchema"> 
      <s:ElementType name="row" content="eltOnly" rs:updatable="true"> 
        <s:AttributeType name="c0" rs:name="value" rs:number="1" rs:keycolumn="true" mifAttrId="1"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
        <s:AttributeType name="c1" rs:name="value" rs:number="2" rs:keycolumn="true" mifAttrId="2"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
     </s:ElementType> 
    </s:Schema> 
    <rs:data> 
        <%set origvalue="    test string   " %>
    <%set results="%string str1='%origvalue%'  function='find' str2='ring'%" %>
    <z:row 
      c0="<%writexml "%origvalue%"%>"  
      c1="<%writexml "%results%"%>"  
    />      
  </rs:data> 
  </xml> 
</InventoryClass> 
</InventoryClasses>

Substring (substr) Source XML:

<?xml version="1.0" encoding="windows-1252"?>
<InventoryClasses>

<InventoryClass name="string_substr" manufacturer='Altiris' description='' platform='Win32' version='1.0' mifClass='Altiris|DSServerIP|1.0'> 
  <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> 
    <s:Schema id="RowsetSchema"> 
      <s:ElementType name="row" content="eltOnly" rs:updatable="true"> 
        <s:AttributeType name="c0" rs:name="orig" rs:number="1" rs:keycolumn="true" mifAttrId="1"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
        <s:AttributeType name="c1" rs:name="final" rs:number="2" rs:keycolumn="true" mifAttrId="2"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
     </s:ElementType> 
    </s:Schema> 
    <rs:data> 
        <%set origvalue="    test string   " %>
    <%set results="%string str1='%origvalue%'  function='substr' start='2' length='5'%" %>
    <z:row 
      c0="<%writexml "%origvalue%"%>"
      c1="<%writexml "%results%"%>"
    />
  </rs:data> 
  </xml> 
</InventoryClass> 
</InventoryClasses> 

Formatting Date & Time in NS Format (NSDateTime) Source XML:

<?xml version="1.0" encoding="windows-1252"?>
<InventoryClasses>

<InventoryClass name="string_nsdatetime" manufacturer='Altiris' description='' platform='Win32' version='1.0' mifClass='Altiris|DSServerIP|1.0'> 
  <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> 
    <s:Schema id="RowsetSchema"> 
      <s:ElementType name="row" content="eltOnly" rs:updatable="true"> 
        <s:AttributeType name="c0" rs:name="string1" rs:number="1" rs:keycolumn="true" mifAttrId="1"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
        <s:AttributeType name="c1" rs:name="results" rs:number="2" rs:keycolumn="true" mifAttrId="2"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
     </s:ElementType> 
    </s:Schema> 
    <rs:data> 
        <%set string1="10/21/2004 12:45:05" %>
    <%set results="%string str1='%string1%' function='nsdatetime'%" %>
    <z:row 
      c0="<%writexml "%string1%"%>"  
      c1="<%writexml "%results%"%>"  
    />      
        <%set string1="10-21-2004 12:45:05" %>
    <%set results="%string str1='%string1%' function='nsdatetime'%" %>
    <z:row 
      c0="<%writexml "%string1%"%>"  
      c1="<%writexml "%results%"%>"  
    />      
        <%set string1="2004/10/21" %>
    <%set results="%string str1='%string1%' function='nsdatetime'%" %>
    <z:row 
      c0="<%writexml "%string1%"%>"  
      c1="<%writexml "%results%"%>"  
    />      
  </rs:data> 
  </xml> 
</InventoryClass> 
</InventoryClasses> 

Replace Function Source XML:

<?xml version="1.0" encoding="windows-1252"?>
<InventoryClasses>

<InventoryClass name="string_replace" manufacturer='Altiris' description='' platform='Win32' version='1.0' mifClass='Altiris|DSServerIP|1.0'> 
  <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> 
    <s:Schema id="RowsetSchema"> 
      <s:ElementType name="row" content="eltOnly" rs:updatable="true"> 
        <s:AttributeType name="c0" rs:name="string1" rs:number="1" rs:keycolumn="true" mifAttrId="1"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
        <s:AttributeType name="c1" rs:name="string2" rs:number="2" rs:keycolumn="true" mifAttrId="2"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
        <s:AttributeType name="c2" rs:name="string3" rs:number="3" rs:keycolumn="true" mifAttrId="3"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
        <s:AttributeType name="c2" rs:name="results" rs:number="3" rs:keycolumn="true" mifAttrId="3"> 
          <s:datatype dt:type="string" dt:maxLength="80"/> 
        </s:AttributeType>
     </s:ElementType> 
    </s:Schema> 
    <rs:data> 
        <%set string1="test string" %>
        <%set string2="test" %>
        <%set string3="real" %>
    <%set results="%string str1='%string1%'  function='replace' str2='%string2%' str3='%string3%' %" %>
    <z:row 
      c0="<%writexml "%string1%"%>"  
      c1="<%writexml "%string2%"%>"  
      c2="<%writexml "%string3%"%>"  
      c3="<%writexml "%results%"%>"  
    />      
  </rs:data> 
  </xml> 
</InventoryClass> 
</InventoryClasses>

Statistics
0 Favorited
1 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Aug 27, 2007 09:35 PM

This is great, I love seeing all the custom inventory information that is being posted on this site. Great job.....
Jonathan

Related Entries and Links

No Related Resource entered.