Split functionality issue

Hey everyone, I’m getting weird functionality with my split functions. Here is an example of a string I’m splitting: ‘|this|is|my|string|variable|’ which is the value of vMyStringVariable

When I do: Split(vMyStringVariable, “|”)(2)
It equals out to: ‘is’
Rather than: ‘is|my|string|variable|’

Anyone else have similar issue? I’ve tried using a different delimiter with the same result.


As you are splitting the string, you will get the value as ‘is’ only

If you use substring then you have to specify the index, so that you can able to get as you require

Hope this helps you


1 Like


Can Do!
I believe that this is working as expected, here is the logic behind what you are doing-

Original String

Split String
{0} -
{1} - this
{2} - is
{3} - my
{4} - string
{5} - variable
{6} -
Select 2nd Element of the split string
{0} -
{1} - this
{2} - is

Why is element 0 and 6 Blank? In your example the pipe (|) delimiter is being used at the beginning and at the end of the string

Here is how I would expect the string to look before splitting it

You should use the delimiter to indicate that one element has ended and that another element exists next to it.
You should not use a delimiter to mark the beginning and ending of your elements

No I understand why 0 is blank I wasn’t asking about that. I was wondering if I’m splitting the string after the third rendition of the pipe character why isn’t it returning everything after the third rendition? Rather it is returning everything in between the third and fourth rendition.

Sort of like the difference between: split(vMyStringVariable, “|”)(3)
And: split(split(vMyStringVariable, “|”)(3), “|”)(0)

I’m used to the split function when I have the same delimiter acting like this:
split(vMyStringVariable, “|”)(3)
Not this: split(split(vMyStringVariable, “|”)(3), “|”)(0)

Which is the behavior I’m seeing now.

when you split an item - you are taking each string that comes before and after a delimiter and assigning it to its own element in an array.
when you add the (2) to the end of your split command, you are specifying that you want the third element of the array resulting from the split command.
I’ll try to test something out for you-
just to confirm: is your desired output ‘is|my|string|variable|’

we are going to expand on the response from @Srini84 with this solution (we will be having some fun with the substring command with a bit of nesting in between!)

Main.xaml (7.9 KB)
@cssc please take a look at this and let me know if it works for you

Input - ‘|this|is|my|string|variable|’
output - ‘is|my|string|variable|’

One last thing- We can try to use some combination of the Split Take and Join Commands to put all of this in a one liner. I’d be very interested in putting that together if you want.

Hey @Mr_Meeseeks I get that the substring option works, I know it works. I’ve just used the split command on prior bots and could have sworn that it was not working in the way it currently does. I mean if I’m splitting a string after the second rendition of a character or word why it give me everything after that but prior to the next rendition of that same word? Shouldn’t it just give me everything after that to the end of the current string?

When we do Split(vMyStringVariable, “|”)(2)

we split the vMyStringVariable string and throw each string into 1 of 7 boxes. Each string has its own box. then we select the string in the 3rd box. We are not selecting the third box and everything that comes after it. However - we can totally do that!
The split command can be used to accomplish what you want, but not without some additional commands.

Is there a way to use only the Split function to get what I’m looking for or do you need the substring for that?

@cssc I figured it out!

Try This: Join(Split(vMyStringVariable,“|”).Skip(2).ToArray,“|”)

got u fam <3 I learned something new - thank you!

Explanation -

  1. Split We split the string and output it as a temporary IEnumerable (all the pipes are gone)
  2. Skip We skip over the first 2 elements in the temporary IEnumerable
  3. ToArray We turn the temporary IEnumerable into a temporary array
  4. Join We turn the temporary array back into a string (we add the pipes back in)

Thanks, appreciate it, that did exactly what I was looking for.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.