Created
July 25, 2012 06:22
-
-
Save qjnz/3174714 to your computer and use it in GitHub Desktop.
Get chars between begin and end chars
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
foreach (var c in GetCharsInBetween('b', 'x')) | |
Console.WriteLine(c); | |
Console.Read(); | |
} | |
private static IEnumerable<char> GetCharsInBetween(char begin, char end) | |
{ | |
if (begin > end) | |
throw new ArgumentException("invalid arguments."); | |
begin = char.ToLower(begin); | |
end = char.ToLower(end); | |
while (begin < end - 1) | |
{ | |
yield return NextChar(begin); | |
begin++; | |
} | |
} | |
private static char NextChar(char c) | |
{ | |
return Convert.ToChar((int)c + 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment