Jump to content

Trim Array UDF


redndahead
 Share

Recommended Posts

Here is a udf I wrote that will trim all the items in an array a specified amount. http://www.autoitscript.com/fileman/users/red/udfs/_arraytrim.au3

;===============================================================================

;

; Description:      Trims all elements in an array a certain number of characters.

; Syntax:              _ArrayTrim( $aArray, $iTrimNum , $iTrimDirection )

; Parameter(s):    $aArray                  - The array to trim the items of.

;                          $iTrimNum              - The amount of characters to trim.

;                          $iTrimDirection        - 0 to trim left, 1 to trim right

; Requirement(s):  None

; Return Value(s):  0 - If invalid array

;                          Otherwise it returns the new trimmed array

; Author(s):          Adam Moore (redndahead)

; Note(s):              None

;

;===============================================================================

Here is some sample code.

$DaysOfWeek = 'Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday'
$WeekArray = StringSplit($DaysOfWeek,'|')
$NewWeekArray = _ArrayTrim($WeekArray,1,1)
For $i = 1 to Ubound($NewWeekArray)
   $WeekText = $WeekText & @CRLF & $NewWeekArray[$i]
Next
MsgBox(0,'Trimmed Days of the Week',$WeekText)
Exit

Output should be:

Monda

Tuesda

Wednesda

Thursda

Frida

Saturda

Sunda

Hope it's useful. =)

red

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...