Smrf.SocialNetworkLib.Twitter.TwitterStatusTextParser.ReplacePunctuationWithSpaces C# (CSharp) Method

ReplacePunctuationWithSpaces() protected method

protected ReplacePunctuationWithSpaces ( String sStatusText ) : String
sStatusText String
return String
    ReplacePunctuationWithSpaces
    (
        String sStatusText
    )
    {
        Debug.Assert(sStatusText != null);
        AssertValid();

        StringBuilder oStringBuilder = new StringBuilder();

        // It's more straightforward to do this with a StringBuilder than with
        // a regular expression.

        foreach (Char c in sStatusText)
        {
            oStringBuilder.Append(

                (
                    // Don't replace "@", which signals the start of a screen
                    // name.

                    c == '@'

                    // Don't replace "_", which is the only punctuation allowed
                    // in a twitter screen name.

                    ||
                    c == '_'

                    // Don't replace alphanumeric characters.

                    ||
                    Char.IsLetterOrDigit(c)
                )

                ? c : ' '
                );
        }

        return ( oStringBuilder.ToString() );
    }