“I have a string where the actual data starts after an id number and a space, how can I split it by the first space and process only the data with Power Automate?”
When you split strings in Power Automate, you can use the expression split(…). You enter the string to split, the separator, and you’ll get back an array with all the pieces. It’s a solution described in one of the previous posts. But what if it’s not that simple? If you don’t want to split the whole string, but split just a part of it? Only at the first occurrence of the separator, and keep the rest untouched?
Split(…) the string anyway
You still want to start with the split(…) expression. Take the whole string and split it. The reason is that even though it’ll split it into multiple pieces, it’ll create an array. And it’s much easier to work with an array. Let’s take an example and split the string by a space.
split(<string to split>, <separator>)
As you can see, the result is an array with each part of the string as a separate item.
Skip(…) the part before the first space
Once you have an array, it’s easy to ignore a piece of it, much easier than to ignore a part of a string. Power Automate has an expression skip(…) exactly for that. The skip(…) expression expects an array and a number of items it should skip.
skip(<array>, <number of items to skip>)
To skip the first item in the array, use the number 1. Extending the expression from above:
skip(split(outputs('Compose'), ' '), 1)
Join(…) the array back into a string
Now, when you removed the undesired item, you can take all the remaining items and turn the array back into a string. With the join(…) expression take the array, define the delimiter, and turn it into a string. It’s the reverse process from the split(…) in the first step, therefore, you should use the same separator.
Following the example in this post, it might look like:
join(skip(split(outputs('Compose'), ' '), 1), ' ')
The result is the original string without the part before the first space.
Power Automate expressions make it easy to split a string by the first space, if you convert it to an array first. It’s much easier to work with, so don’t be afraid to use it. You can navigate an array, skip or take part of it, and when you’re done, you can easily convert it back to a string. You don’t care about the string length, or how long is the part to skip, all the things you’d have to do if you kept it as a string…