For situations where you might have a need for text that can scroll,
just a little simple toy method that'll allow you to efficiently
generate the strings for such.
public IEnumerable<string> ScrollableText(string text, int charactersToDisplay)
{
if (string.IsNullOrWhiteSpace(text))
throw new ArgumentException("Text cannot be null, empty, or whitespace.", "text");
if (charactersToDisplay < 1)
throw new ArgumentException("You must specify at least one character to display.", "charactersToDisplay");
string[] states;
if (text.Length <= charactersToDisplay)
{
states = new string[] { text };
}
else
{
states = new string[text.Length];
string sourceString = string.Concat(text, text);
for (int i = 0; i < text.Length; ++i)
states[i] = sourceString.Substring(i, charactersToDisplay);
}
int index = 0;
while (true)
{
yield return states[index];
if (++index >= states.Length)
index = 0;
}
}