
the typical good solution to this problem in c or c++ is to use a
string reverse function on the entire buffer, then re-reverse each
word. this leaves multiple spaces correctly embedded in the larger
string.
that approach, of course, won't work in haskell, since it relies on
updates. but if the challenge includes transforming "one two three
four " into " four three two one", how could this be done?
On 12/10/06, Neil Mitchell
Hi
However, every response to this question I've seen (admittedly only three or four so far) used StringBuilder. When I ask, "why not use Join?" most C# programmers seem to respond that StringBuilder is "faster" (I haven't measured the difference in performance).
I don't know, but I'd be really surprised if Join wasn't implemented in terms of StringBuilder at worst. Possibly it does a summation of the lengths of the String's in the list, and does exactly one allocation, making it much more efficient. Either way, if there is a function in the libraries, you shouldn't be able to write one which is faster!
I suspect people saying "use StringBuilder" have read an article on a website telling them that String concat is slow - but haven't thought about the implications...
Thanks
Neil _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe