String operations

Is there a way to perform additional operations on string values?  I need to be able to truncate a string if greater than a certain length and have a value that I need to parse/split into two parts.  How can I best accomplish this?

As an example, if I return the "Author" field from a list item, it returns in the form: "{UserID};#{UserName}".  I don't want to display the UserID value, so I'd need a way to pull just the UserName portion out of the field value.

Have more questions? Submit a request

3 Comments

  • 0
    Avatar
    Matthew McBride

    Do you have an example using the $Expressions.Split function?  I used:

    #set( $authorParts = $Expressions.Split($dataRow.get_item("Author"), ";#") )

    but I can't figure out the correct syntax to render the array elements returned by the Split method.  For instance, $authorParts[0] renders "System.String[[0]".

  • 0
    Avatar
    Fernandes, Denzil

    this works...try it

    <br>
    #set ( $input = "1a2a1b2b" )
    #set ( $test = $Expressions.Split($input, "1"))
    $Strings.Format($test.get(1))
    <br>

  • 0
    Avatar
    Fernandes, Denzil

    Got it Jeremy.. Check out my solution using DataZoom to read All Web Applications and Their Respective Application Pools..

    The trick was to use $Strings.Format before getting the item in the array...


    #set ( $WebApps = $webApplication.WebService.WebApplications )
    #set ( $Farm = $webApplication.WebService.Farm )
    <span class="ms-vb"> $Farm </span><br>


    #foreach($WebApp in $WebApps)
      #beforeall
        <table class="ms-listviewtable" cellpadding="3" cellspacing="0" border="0" width="100%">
          <tr class="ms-viewheadertr">
            <th class="ms-vh2-nofilter">Display Name</th>
            <th class="ms-vh2-nofilter">Application Pool</th>
          </tr>
      #odd
          <tr class="">
      #even
          <tr class="ms-alternating">
      #each
            <td class="ms-vb2">$WebApp.DisplayName</td>
     #set ( $WebAppPoolPropertyValue = $Strings.Format("$WebApp.ApplicationPool") )
     #set ( $WebAppPoolName = $Expressions.Split("$WebAppPoolPropertyValue", "="))
     
            <td class="ms-vb2">$Strings.Format($WebAppPoolName.get(1))<td>
      #after
          </tr>
      #afterall
        </table>
      #nodata
        No lists found
    #end

     

Please sign in to leave a comment.