#Splitting on one or more occurrences
Splitting on one or more occurrences
Say you have a string "abbcdbbfghbdbb" and you want to split it on b
"abbcdbbfghbdbb"'b/
This leaves on stack:
["a" "" "cd" "" "fgh" "d" "" ""]
Notice the empty strings ? Those are there because two b were together and nothing was in between them. At times, you want to avoid this. You can do this by
"abbcdbbfghbdbb"'b/La-
or filtering out empty strings
"abbcdbbfghbdbb"'b/{},
but that is 3 extra bytes.
A little less known operator for this particular use case is %. Apart from doing mod and map and splitting based on number ("abcd"2% = "ac"), % can also split on strings/arrays. So for the above use case:
"abbcdbbfghbdbb"'b%
will leave
["a" "cd" "fgh" "d"]
on stack.
Thanks for @user23013 for pointing this out in one of my answers today.
#Splitting on one or more occurrences
Say you have a string "abbcdbbfghbdbb" and you want to split it on b
"abbcdbbfghbdbb"'b/
This leaves on stack:
["a" "" "cd" "" "fgh" "d" "" ""]
Notice the empty strings ? Those are there because two b were together and nothing was in between them. At times, you want to avoid this. You can do this by
"abbcdbbfghbdbb"'b/La-
or filtering out empty strings
"abbcdbbfghbdbb"'b/{},
but that is 3 extra bytes.
A little less known operator for this particular use case is %. Apart from doing mod and map and splitting based on number ("abcd"2% = "ac"), % can also split on strings/arrays. So for the above use case:
"abbcdbbfghbdbb"'b%
will leave
["a" "cd" "fgh" "d"]
on stack.
Thanks for @user23013 for pointing this out in one of my answers today.
Splitting on one or more occurrences
Say you have a string "abbcdbbfghbdbb" and you want to split it on b
"abbcdbbfghbdbb"'b/
This leaves on stack:
["a" "" "cd" "" "fgh" "d" "" ""]
Notice the empty strings ? Those are there because two b were together and nothing was in between them. At times, you want to avoid this. You can do this by
"abbcdbbfghbdbb"'b/La-
or filtering out empty strings
"abbcdbbfghbdbb"'b/{},
but that is 3 extra bytes.
A little less known operator for this particular use case is %. Apart from doing mod and map and splitting based on number ("abcd"2% = "ac"), % can also split on strings/arrays. So for the above use case:
"abbcdbbfghbdbb"'b%
will leave
["a" "cd" "fgh" "d"]
on stack.
Thanks for @user23013 for pointing this out in one of my answers today.
#Splitting on one or more occurrences
Say you have a string "abbcdbbfghbdbb" and you want to split it on b
"abbcdbbfghbdbb"'b/
This leaves on stack:
["a" "" "cd" "" "fgh" "d" "" ""]
Notice the empty strings ? Those are there because two b were together and nothing was in between them. At times, you want to avoid this. You can do this by
"abbcdbbfghbdbb"'b/La-
or filtering out empty strings
"abbcdbbfghbdbb"'b/{},
but that is 3 extra bytes.
A little less known operator for this particular use case is %. Apart from doing mod and map and splitting based on number ("abcd"2% = "ac"), % can also split on strings/arrays. So for the above use case:
"abbcdbbfghbdbb"'b%
will leave
["a" "cd" "fgh" "d"]
on stack.
Thanks for @user23013 for pointing this out in one of my answers today.