Seperating string ad integer in array

Hi Team,
i have following array,

i want the output as below from Mentioned Array
Student1 80
Student2 90
Student3 100
Student4 80

would this be possible by LINQ… pls help

Hi @Devasaiprasad_Kakumanu ,

Still a bit not clear on the Output representation, but could check with the below if it is the Expectation :

Array2.Chunk(2).Select(Function(x)String.Join(" ",x)).ToArray

From Debug :

image

1 Like

@Devasaiprasad_Kakumanu

If you have the need to store the values in the array in a DT then, you could use a simple counter based loop to achieve this.

wordked Bro… THanks dear… is there any Documentation you can share to understand LINQ Functions

@Devasaiprasad_Kakumanu ,

Would suggest to go through the Tutorial/Docs on the below post :

The content keeps on getting updated in the post.

Also, Could refer on some Youtube videos :

@Devasaiprasad_Kakumanu

Array:

string data = { “Student1”, “80”, “Student2”, “90”, “Student3”, “100”, “Student4”, “80” };

Use this Linq:

var result = data.Select((value, index) => new { Student = value, Score = data[index + 1] })
.Where((item, index) => index % 2 == 0)
.Select(item => $“{item.Student} {item.Score}”);

  1. We first use the Select method to project the array elements into pairs of “Student” and “Score” based on their positions in the array.
  2. Then, we use the Where method to filter out every other item, starting with the first one (index 0), effectively selecting the “Student” elements.
  3. Finally, we use another Select to format the pairs as “Student Score” strings, which is your desired output.

Output:

Student1 80
Student2 90
Student3 100
Student4 80

Cheers…!

@Devasaiprasad_Kakumanu

str.Chunk(2).Select(Function(x)String.Join(" ",x)).ToArray

cheers…!