score:1
{
"1,3",
"4,6",
"7,9",
"10,12"
};
score:1
//----------------linq.----------------------
//data source
var source = new list<string> { "1,2,3", "4,5,6", "7,8,9", "10,11,12" };
//var sourcetest = new list<string> { "11,45,6,5,", "2,3,4,5,6", "1,7,40,30", "10,20,30,40,50" };
//var sourcetest2 = new list<string> { "15,12,11,45,6,5,", "1,2,3,4,5,6", "1,7,9,40,30", "60,20,70,80,90,100" };
//query creation
var querylambda = source.select(item => new
{
firstitem = item.split(',').firstordefault(),
thirditem = item.split(',').skip(2).firstordefault()
}).tolist();
var query = (from items in source
select new
{
firstitem = items.split(',').firstordefault(),
thirditem = items.split(',').skip(2).firstordefault()
}).tolist();
//query execution
querylambda.foreach(item => { console.writeline(string.join(",", new string[] { item.firstitem, item.thirditem })); });
console.writeline();
query.foreach(item => { console.writeline(string.join(",", new string[] { item.firstitem, item.thirditem })); });
console.readline();
score:2
ienumerable<tuple<string, string>> parsed = list.select(
s => (s.split(',')[0], s.split(',')[2]));
Source: stackoverflow.com
Related Query
- How to extract items at specified locations from list of comma separated strings using LINQ
- How can I get a comma separated list of values from a List using LINQ?
- Extract common string from two strings with Comma separated
- How can I use Linq to find items with matching words from a comma separated string?
- How do I concatenate the items from the list into a comma delimited string in LINQ
- How to get duplicate items from a list using LINQ?
- how to remove empty strings from list, then remove duplicate values from a list
- How to Quickly Remove Items From a List
- LINQ: How to get items from an inner list into one list?
- How do I move items from a list to another list in C#?
- Linq - How to select items from a list that contains only items of another list?
- How can I extract a list of Tuple from a specific table with Entity Framework / LINQ?
- Using LINQ to extract ints from a list of strings
- How to find a match with 2 comma separated strings with LINQ
- How to create a comma delimited string from distinct list of values using LINQ?
- How to generate a unique list of items from another list using LINQ in C#
- How to use LINQ to query list of strings that do not contain substring entries from another list
- LINQ DynamicLibrary: How to extract count and list from IQueryable
- how to get duplicate items from a list in vb.net
- how to extract common part from a string list using C#
- How to Pass a List of Items from View to Controller (ASP.NET MVC 4)
- How to Select the Token and Index from a Comma Separated String in Linq
- How do I compare items from a list to all others without repetition?
- In EF Core, how can I perform a group by and select a list of comma separated values?
- How to check for null values before Converting a comma Separated string to Generic List
- How to remove substring from all strings in a list in C# using LINQ
- How to remove from one list all the items in another?
- To determine if one of the Strings from a list contains the initial part of a specified string using LINQ
- How to select certain strings (by index) from a list in a list with linq?
- How to return list of items from linq to sql query and call it in a console application
More Query from same tag
- Query in C#: how to find data by only 1 number, for example?
- BLToolkit equivalent of LoadWith from L2S
- Generic lists: The type arguments for method cannot be inferred from the usage in lambdas
- C#, entity framework, linq how to exclude property
- how to populate navigational properties when using Entity Framework
- Return Distinct Objects with Linq
- How to create a string[] within a LINQ query via Regex.Split()
- Concat and/or merge objects in two generic lists
- Linq To Sql : SQL Default Value overridden
- can't see anonymous type values without using .FirstOrDefault() ?
- Dynamic Linq To Sql With ComboBox and Column.Contains
- EF6 Linq Query .Include only returning first entry of child table
- How to make a property unique in Entity Framework Code First
- Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?
- C# Linq to json how to extract a properties that contain a certains values
- Using LINQ, how do I choose items at particular indexes?
- Can you create a grouping based on ranges?
- How do I properly convert a string to decimal in my linq query?
- Merge two string fields with LINQ into a string array
- Select entire duplicate row from datatable with linq c#
- LINQ for removing elements that are started with other element from list
- Is FirstOrDefault/First and OrderByDescending, quicker than LastOrDefault/Last and OrderBy?
- LINQ table enumeration with column enumeration
- Inner join with linqJS
- Selecting count in LINQ
- Event delegates disappear after being added in a foreach loop
- Linq strange behviour with dictionaries
- Skip and Take is generating exception in Entity Framework
- LINQ query, using relationships
- Linq to XML - Weird where results