I try two ways but not working:
I want to extract the first line of my “list”. What I’m missing?
Thanks in advance
Can’t you use
My list is a multi line string, not an array
Not working, sorry
If you want the first line of a multiline string you can use
Not working on scriptable but working good on other environments. Maybe the syntax is not correct. Scriptable shown this template when I write the code:
What error does it produce? Or what does it return?
The question mark behind the argument name means that the argument itself is optional. So you could technically call it without any arguments, but I currently don’t know what it then does…
split("\n") definitely does work in Scriptable, as you can see if you run this short bit of test code:
a = `First line
b = a.split("\n");
So if it’s “not working” for you, the problem is likely to be either
- The variable you’re applying
split to doesn’t contain the text you think it does.
- The text doesn’t use the linefeed character to separate lines.
Sometimes lines are separated by a combination of carriage return and linefeed characters; less common is a carriage return by itself. It depends on where the text came from. If the separator is the problem, there are ways to handle that.
But, as @schl3ck suggests, without seeing your code or the data it’s operating on, we don’t have enough information to help you.
Sorry but yes its works. I don’t know what happens the first time I try it
I’m unfamiliar with the
[b] = construction. Is it basically a case that it’s throwing away every element of the list other than the first (which it stores in b)?
It’s a destructuring assignment of the array.
Right. I guess the new-to-me bit is the idea you can just keep the first and throw away the rest.