fCraft.Color.StripColors C# (CSharp) Method

StripColors() public static method

Strips all ampersand color codes, and unescapes doubled-up ampersands.
public static StripColors ( [ input ) : string
input [
return string
        public static string StripColors( [NotNull] string input ) {
            if ( input == null )
                throw new ArgumentNullException( "input" );
            if ( input.IndexOf( '&' ) == -1 ) {
                return input;
            } else {
                StringBuilder output = new StringBuilder( input.Length );
                for ( int i = 0; i < input.Length; i++ ) {
                    if ( input[i] == '&' ) {
                        if ( i == input.Length - 1 ) {
                            break;
                        } else if ( input[i + 1] == '&' ) {
                            output.Append( '&' );
                        }
                        i++;
                    } else {
                        output.Append( input[i] );
                    }
                }
                return output.ToString();
            }
        }

Usage Example

Example #1
0
        public static void Log(LogType type, [NotNull] string message, [NotNull] params object[] args)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (args.Length > 0)
            {
                try
                {
                    message = String.Format(message, args);
                }
                catch (Exception e) {
                    message = e.StackTrace + "\n" + message;
                }
            }
            if (!Enabled)
            {
                return;
            }

            message = Color.StripColors(message, true);
            string line = DateTime.Now.ToString(TimeFormat, formatter) + " > " + GetPrefix(type) + message;     // localized

            lock ( LogLock ) {
                RaiseLoggedEvent(message, line, type);

                RecentMessages.Enqueue(line);
                while (RecentMessages.Count > MaxRecentMessages)
                {
                    RecentMessages.Dequeue();
                }

                if (LogFileOptions[(int)type])
                {
                    try {
                        File.AppendAllText(Path.Combine(Paths.LogPath, CurrentLogFileName),
                                           line + Environment.NewLine);
                    } catch (Exception ex) {
                        string errorMessage = "Logger.Log: " + ex;
                        line = String.Format("{0} > {1}{2}",
                                             DateTime.Now.ToString(TimeFormat, formatter),   // localized
                                             GetPrefix(LogType.Error),
                                             errorMessage);
                        RaiseLoggedEvent(errorMessage,
                                         line,
                                         LogType.Error);
                    }
                }
            }
        }
All Usage Examples Of fCraft.Color::StripColors