Home > Software design >  Using linq in .net core to parse a string and turn it into a list
Using linq in .net core to parse a string and turn it into a list

Time:08-16

I have a string that gets input like say: abcde.

I then want to take that string and do the following:

  1. Make the string uppercase
  2. Parse the string to get each character one by one
  3. Add a prefix to that new string (prefix is H-I)
  4. Return a list of every new string in order.

So using abcde the resulting list should be:

// new list items being returned
H-IA
H-IB
H-IC
H-ID
H-IE

I know there should be an easy way to do this with Linq but don't quite have it yet.

CodePudding user response:

In a line

var list = str.ToUpper().ToArray().Select(c => "H-1"   c).ToList();
  • Related