Automic Workload Automation

  • 1.  Splitting a string to get last 3 characters

    Posted Oct 03, 2018 11:09 AM

    Hi,

    I want to pull back the last 3 characters of a given string but don't know if that's possible in Automic. 

     

    I tried to use this syntax but it doesn't like the -3

     

    :SET &LENGTH# = STR_LENGTH(&NAME#)
    :SET &ENV# = SUBSTR(&NAME#,&LENGTH#,-3)
    :PRINT &ENV#

     

    Anyone know how  I can archive this?

     

    Thanks,

    John.



  • 2.  Re: Splitting a string to get last 3 characters

    Posted Oct 03, 2018 11:15 AM
    :SET &Input# = "ABC123"
    :SET &Length# = STR_LENGTH(&Input#)
    :SET &Cut_Start# = &Length# - 2
    :SET &Output# = STR_CUT(&Input#,&Cut_Start#,3)
    :PRINT &Output#


  • 3.  Re: Splitting a string to get last 3 characters

    Posted Oct 03, 2018 11:16 AM

    Thanks Michael...



  • 4.  Re: Splitting a string to get last 3 characters

    Posted Oct 03, 2018 11:18 AM

    Try this:

     

    :set &length# = str_length(&NAME#)
    :set &start_pos# = sub(&length#,2)
    :if &start_pos# < 1
    :  set &start_pos# = 1
    :endif
    :SET &ENV# = SUBSTR(&NAME#,&start_pos#)

    :print "last 3 chars of '&NAME#' is '&ENV#'"


  • 5.  Re: Splitting a string to get last 3 characters

    Posted Oct 03, 2018 11:52 AM

    Here is another way:

    : set &str# = 'ABCDEFG'
    : set &str# = str_reverse(&str#)
    : set &str# = substr(&str#, 1, 3)
    : set &str# = str_reverse(&str#)
    : print &str#