Click here to Skip to main content
13,347,998 members (54,365 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 31 Aug 2012

Scrolling Text

, 31 Aug 2012
Rate this:
Please Sign up or sign in to vote.
A function to generate an endless collection of scrolling text for your use/amusement.

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 };
        states = new string[text.Length];

        string sourceString = string.Concat(text, text);
        // Build the different states of the scrolling text.
        for (int i = 0; i < text.Length; ++i)
            states[i] = sourceString.Substring(i, charactersToDisplay);

    int index = 0;
    // Cycle through the different states of the scrolling text, ad nauseum.
    while (true)
        yield return states[index];
        if (++index >= states.Length)
            index = 0;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Andrew Rissing
Software Developer (Senior)
United States United States
Since I've begun my profession as a software developer, I've learned one important fact - change is inevitable. Requirements change, code changes, and life changes.

So..If you're not moving forward, you're moving backwards.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Christian Amado2-Sep-12 6:07
memberChristian Amado2-Sep-12 6:07 
Very useful!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 31 Aug 2012
Article Copyright 2012 by Andrew Rissing
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid