Automic Workload Automation

 View Only
  • 1.  How to split a string by newline

    Posted Jan 18, 2019 09:29 AM

    Hi,

    is it possible to split a string by newline?

    I have tried passing \n and UC_CRLF() but it does not work.

     

    Thanks in advance,

    Marco



  • 2.  Re: How to split a string by newline

    Posted Jan 18, 2019 09:37 AM


  • 3.  Re: How to split a string by newline

    Posted Jan 18, 2019 10:58 AM
      |   view attached

    I just tested my approach of setting &Newline# in an object variable, and it works fine as a separator for STR_SPLIT. See the attached SCRI for a demonstration.

    Attachment(s)



  • 4.  Re: How to split a string by newline

    Posted Jan 21, 2019 05:52 AM
      |   view attached

    If you want to find newline characters in multi-line strings, you must first set a variable to the character for which you are searching. There are two straightforward ways to do this:

    1. Set a script variable to the value returned by UC_CRLF().

      :SET &CRLF# = UC_CRLF()

    2. Set object variable to just a newline character.

     

    In my experience, these approaches do not work consistently. I did a quick test to compare the characters being written to these variables.

    Script

    :SET &CRLF_POS_IN_NL# = STR_FIND(&NEWLINE#,&CRLF#)
    :PRINT &&CRLF_POS_IN_NL#: &CRLF_POS_IN_NL#
    :SET &NL_POS_IN_CRLF# = STR_FIND(&CRLF#,&NEWLINE#)
    :PRINT &&NL_POS_IN_CRLF#: &NL_POS_IN_CRLF#

    Results

    U00020408 &CRLF_POS_IN_NL#: 0000000000000000
    U00020408 &NL_POS_IN_CRLF#: 0000000000000002

     

    From this, I conclude:

    1. The AE script function UC_CRLF() returns an MS-DOS-style newline: a carriage return and a line feed (CR LF or \r \n).
    2. In multi-line object variables and other multi-line fields in the Automation Engine, the newline character is a UNIX-style newline: just the line feed character (LF or \n)*.

     

    I also found that when the AE writes a string to a file via an OS agent, it automatically converts newline characters to the style specific to that OS. See the attached JOBS object for an example.

     

    * The newline character used internally by the AE might depend on the OS or database of the AE server.

    Attachment(s)



  • 5.  Re: How to split a string by newline

    Posted Jan 22, 2019 09:45 AM
    1. The AE script function UC_CRLF() returns an MS-DOS-style newline: a carriage return and a line feed (CR LF or \r \n).
    2. In multi-line object variables and other multi-line fields in the Automation Engine, the newline character is a UNIX-style newline: just the line feed character (LF or \n)*.

     

    I just confirmed this using the HEX() script function.

     

    Script

    :SET &CRLF_HEX# = HEX(&CRLF#)
    :PRINT &&CRLF_HEX#: &CRLF_HEX#
    :SET &NEWLINE_HEX# = HEX(&NEWLINE#)
    :PRINT &&NEWLINE_HEX#: &NEWLINE_HEX#

    Results

    U00020408 &CRLF_HEX#: 0D0A
    U00020408 &NEWLINE_HEX#: 0A

     

    In ASCII, hex 0A (decimal 10) is the linefeed character, and hex 0D (decimal 13) is the carriage return character.