Quantcast
Channel: User user2023861 - Code Review Stack Exchange
Viewing all articles
Browse latest Browse all 35

Answer by user2023861 for Swapping characters pairs in a string

$
0
0

Finally, an excuse to use the Zip extension method:

private static string StringSwap2(string stringToSwap){    if ((stringToSwap.Length % 2).Equals(1))    {        stringToSwap += "";    }    var evens = stringToSwap.Where((w, i) => i % 2 == 0);    var odds = stringToSwap.Where((w, i) => i % 2 == 1);    var zipped = evens.Zip(odds, (left, right) => string.Concat(right, left));    return string.Concat(zipped);}

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>