Quantcast
Channel: Using LINQ to concatenate strings - Stack Overflow
Browsing latest articles
Browse All 18 View Live

Answer by Alex from Jitbit for Using LINQ to concatenate strings

FWIW I benchmarked string.Join vs .Aggregate on a string array of 15 strings using BDN:MethodMeanErrorStdDevGen0AllocatedString_Join92.99 ns9.905 ns0.543 ns0.0560352 BLING_Aggregate406.00 ns74.662...

View Article



Answer by brichins for Using LINQ to concatenate strings

Here is the combined Join/Linq approach I settled on after looking at the other answers and the issues addressed in a similar question (namely that Aggregate and Concatenate fail with 0...

View Article

Answer by cdiggins for Using LINQ to concatenate strings

Here it is using pure LINQ as a single expression: static string StringJoin(string sep, IEnumerable<string> strings) { return strings .Skip(1) .Aggregate( new...

View Article

Answer by tpower for Using LINQ to concatenate strings

By 'super-cool LINQ way' you might be talking about the way that LINQ makes functional programming a lot more palatable with the use of extension methods. I mean, the syntactic sugar that allows...

View Article

Answer by Andy S. for Using LINQ to concatenate strings

I did the following quick and dirty when parsing an IIS log file using linq, it worked @ 1 million lines pretty well (15 seconds), although got an out of memory error when trying 2 millions lines....

View Article


Answer by Chris Marisic for Using LINQ to concatenate strings

I'm going to cheat a little and throw out a new answer to this that seems to sum up the best of everything on here instead of sticking it inside of a comment. So you can one line...

View Article

Answer by Andiih for Using LINQ to concatenate strings

You can combine LINQ and string.join() quite effectively. Here I am removing an item from a string. There are better ways of doing this too but here it is:filterset = String.Join(",",...

View Article

Answer by jonathan.s for Using LINQ to concatenate strings

You can use StringBuilder in Aggregate: List<string> strings = new List<string>() { "one", "two", "three" }; StringBuilder sb = strings .Select(s => s) .Aggregate(new StringBuilder(),...

View Article


Answer by user337754 for Using LINQ to concatenate strings

quick performance data for the StringBuilder vs Select & Aggregate case over 3000 elements:Unit test - Duration (seconds)LINQ_StringBuilder - 0.0036644LINQ_Select.Aggregate - 1.8012535...

View Article


Answer by Kelly for Using LINQ to concatenate strings

Lots of choices here. You can use LINQ and a StringBuilder so you get the performance too like so:StringBuilder builder = new StringBuilder();List<string> MyList = new List<string>()...

View Article

Answer by Patrik Hägne for Using LINQ to concatenate strings

I blogged about this a while ago, what I did seams to be exactly what you're looking for:http://ondevelopment.blogspot.com/2009/02/string-concatenation-made-easy.htmlIn the blog post describe how to...

View Article

Answer by Kieran Benton for Using LINQ to concatenate strings

I always use the extension method:public static string JoinAsString<T>(this IEnumerable<T> input, string seperator){ var ar = input.Select(i => i.ToString()); return...

View Article

Answer by Amy B for Using LINQ to concatenate strings

return string.Join(", ", strings.ToArray());In .Net 4, there's a new overload for string.Join that accepts IEnumerable<string>. The code would then look like:return string.Join(", ", strings);

View Article


Answer by Jorge Ferreira for Using LINQ to concatenate strings

This answer shows usage of LINQ (Aggregate) as requested in the question and is not intended for everyday use. Because this does not use a StringBuilder it will have horrible performance for very long...

View Article

Answer by Daniel Earwicker for Using LINQ to concatenate strings

Real example from my code:return selected.Select(query => query.Name).Aggregate((a, b) => a +", "+ b);A query is an object that has a Name property which is a string, and I want the names of all...

View Article


Answer by Armin Ronacher for Using LINQ to concatenate strings

Why use Linq?string[] s = {"foo", "bar", "baz"};Console.WriteLine(String.Join(", ", s));That works perfectly and accepts any IEnumerable<string> as far as I remember. No need Aggregate anything...

View Article

Answer by Robert S. for Using LINQ to concatenate strings

Have you looked at the Aggregate extension method?var sa = (new[] { "yabba", "dabba", "doo" }).Aggregate((a,b) => a +","+ b);

View Article


Using LINQ to concatenate strings

What is the most efficient way to write the old-school:StringBuilder sb = new StringBuilder();if (strings.Count > 0){ foreach (string s in strings) { sb.Append(s +", "); } sb.Remove(sb.Length - 2,...

View Article
Browsing latest articles
Browse All 18 View Live


Latest Images