Created
November 19, 2018 08:28
-
-
Save kipusoep/ec9c25300bba81bab10144246391af5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Replaces the <see cref="regexEscapedSearch" /> occurrences with <see cref="oddReplace" /> and <see cref="evenReplace"/> | |
/// </summary> | |
/// <param name="input">The input string</param> | |
/// <param name="regexEscapedSearch">The string to search for (escaped for usage in regex)</param> | |
/// <param name="oddReplace">To replace odd occurrences with</param> | |
/// <param name="evenReplace">To replace even occurrences with</param> | |
/// <returns></returns> | |
public static string ReplaceOddEvenOccurrences(this string input, string regexEscapedSearch, string oddReplace, string evenReplace) | |
{ | |
var i = 0; | |
return new Regex(regexEscapedSearch).Replace(input, m => i++ % 2 == 0 ? oddReplace : evenReplace); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment