Split string on newline

Answered Question
Jul 16th, 2013
User Badges:

G'day,

I'm writing a process that takes as input a multiline string. I need to chop this string up via newlines and iterate through each one but I can't work out how to split a string based on newlines and the TEO Reference Guide is suitably vague on what special characters (if any) one can split a string on .


This process is intended to be initiated directly via TEOWebConsole at this stage else I would implement this in CCP instead.


Thoughts?

Correct Answer by Christopher Roberts about 4 years 1 month ago

You can use the regex ^.*$


and then feed in the string and then loop through it, trim off the ends and go from there.


I have a TAP of some commonly used functions that I use in many of my automations. I call it the Automation Function Tools. I have uploaded the zipped tap to here. Download it, unzip, and import.


It has a function called convert multi-line to single-line string. While that might not be exactly what you are doing, you can pull the pieces out for the breaking at newline and be ok I think.



Here's a screenshot of what I mean:





--shaun

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 4.5 (2 ratings)
Loading.
Correct Answer
Christopher Roberts Wed, 07/17/2013 - 03:37
User Badges:
  • Cisco Employee,

You can use the regex ^.*$


and then feed in the string and then loop through it, trim off the ends and go from there.


I have a TAP of some commonly used functions that I use in many of my automations. I call it the Automation Function Tools. I have uploaded the zipped tap to here. Download it, unzip, and import.


It has a function called convert multi-line to single-line string. While that might not be exactly what you are doing, you can pull the pieces out for the breaking at newline and be ok I think.



Here's a screenshot of what I mean:





--shaun

rruckley Wed, 07/17/2013 - 15:40
User Badges:

Chris,

     Thats excellent news. I was hoping the split string could understand special characters like tab and newline but a regex works fine for me. I even tried passing the string to a powershell script but of course multiline strings aren't supported with powershell!


     I'm guessing if I rename the extension to your attachement as .tap then I should be able to import that directly?


     Otherwise, my is [email protected]


     Thanks.


Ryan

Christopher Roberts Wed, 07/17/2013 - 16:07
User Badges:
  • Cisco Employee,

Ryan,

It's a TAP file inside of a zip. Show extract the TAP from the zip using your favorite .zip extracter then you should be able to import.


--shaun

Actions

This Discussion

Related Content