Manipulate a list of strings

Is there a way to manipulate a list where a hyphen is found using Linq? No other special characters should be altered, but new list items should be created:

The input list contains {Jack-Jones, Smith-Western}

The output list should show the hypen, reverse the given list item with the hypen, remove the hyphen, then split the string where the hypen was found:

The Output should look like:
{Jack-Jones, Jones-Jack, Jack Jones, Jones Jack,Jack, Jones, Smith-Western, Western-Smith, Smith Western, Western Smith, Smith, Western}

I’ve tried to use linq split, replace & orderby, but i’ve not had much success.

Thank you

Hello @qwerty1

I have done the array manipulation by using split. I have stored the data in a array variable.
Use for each to iterate for every item. I splitted the current item by “-”(hyphen).
I took another array variable to store the structure that I need.

Same you can done with the lists. Find the below picture for the process steps.

Regards, It may help you.

Thank you for your message, but i’d prefer to do this without having to loop through the array. Is there a way that this can be achieved using linq?
@Yoichi are you able to offer some guidance please?

Okay @qwerty1 . I’ll try to do it but the above process doesn’t taking much automation time.

Hi @qwerty1 ,

Try this:

{"Jack-Jones", "Smith-Western"}.SelectMany(Function(s) If(s.Contains("-"c), {s, String.Format("{0}-{1}", s.Split("-"c)(1), s.Split("-"c)(0)), s.Replace("-", " "), String.Format("{0} {1}", s.Split("-"c)(1), s.Split("-"c)(0)), s.Split("-"c)(0), s.Split("-"c)(1)}, {s})).ToArray()

Regards,

1 Like

Thank you - it works perfectly

1 Like

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