I know split is a useful tool and I know there is a way to do this. I tried a few different methods but couldn’t figure it out via google. Can anyone help me.
example1 = "test1,test2,test3,test4,test5"
example2 = "test1,test2,test3,test4,test5,test6,test7"
So I need the result to look like this
example1 = test3,test4,test5
example2 = test5,test6,test7
I would like to keep the comma’s too.
This is basically just
splitandjoinon commas. Negative indexes into an array will easily get you the last however-many elements. So I think you wantstr.split(',')[-3..-1].join(',').