SETRIGHT Extract right substring |
Top Previous Next |
This script command extracts the rightmost [ cnt ] characters from [ value ] and saves the result in [ variable ].
If the /split option is specified, the unextracted portion of [ value ] is assigned back to [ value ] replacing the original value.
Consider the following example.
;; assign a variable to a string SET string = "this is a string" ;; extract the rightmost 6 characters SETRIGHT substring = string 6
;; another example of syntax to extract the rightmost 6 characters SETNUM len = 6 SETRIGHT substring = string len
The resulting substring variable contains the value "string". The original string variable is unchanged.
Consider the same example using the /split option to remove a 4 character extension from a file's name.
;; We start with a file name in standard DOS 8.3 format SET filename = "ReadMe.txt" ;; extract the rightmost 4 characters SETRIGHT extension = filename 4 /split
The resulting extension variable contains the value ".txt" and the remaining original "ReadMe" is stored in the filename variable. Use the SETEXTRACT command to parse filenames that have variable length extensions.
Related command(s): SETLEFT, SETMID, SETLEN, SETEXTRACT, SETSUBSTR, SET, SETREPLACE |