fCraft.Color.SubstituteSpecialColors C# (CSharp) Method

SubstituteSpecialColors() public static method

public static SubstituteSpecialColors ( [ input ) : string
input [
return string
        public static string SubstituteSpecialColors( [NotNull] string input ) {
            if ( input == null )
                throw new ArgumentNullException( "input" );
            StringBuilder sb = new StringBuilder( input );
            for ( int i = sb.Length - 1; i > 0; i-- ) {
                if ( sb[i - 1] == '&' ) {
                    switch ( Char.ToLower( sb[i] ) ) {
                        case 's':
                            sb[i] = Sys[1];
                            break;

                        case 'y':
                            sb[i] = Say[1];
                            break;

                        case 'p':
                            sb[i] = PM[1];
                            break;

                        case 'r':
                            sb[i] = Announcement[1];
                            break;

                        case 'h':
                            sb[i] = Help[1];
                            break;

                        case 'w':
                            sb[i] = Warning[1];
                            break;

                        case 'm':
                            sb[i] = Me[1];
                            break;

                        case 'i':
                            sb[i] = IRC[1];
                            break;

                        default:
                            if ( IsValidColorCode( sb[i] ) ) {
                                continue;
                            } else {
                                sb.Remove( i - 1, 1 );
                            }
                            break;
                    }
                }
            }
            return sb.ToString();
        }

Same methods

Color::SubstituteSpecialColors ( [ sb ) : void

Usage Example

Example #1
0
        public static Packet MakeExtAddPlayerName(short nameId, string playerName, string listName, string groupName,
                                                  byte groupRank, bool useFallbacks, bool hasCP437)
        {
            if (playerName == null)
            {
                throw new ArgumentNullException("playerName");
            }
            if (listName == null)
            {
                throw new ArgumentNullException("listName");
            }
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            Packet packet = new Packet(OpCode.ExtAddPlayerName);

            //Logger.Log(LogType.Debug, "Send: MakeExtAddPlayerName({0}, {1}, {2}, {3}, {4})", nameId, playerName, listName, groupName, groupRank);
            WriteI16(nameId, packet.Bytes, 1);
            PacketWriter.WriteString(Color.SubstituteSpecialColors(playerName, useFallbacks), packet.Bytes, 3, hasCP437);
            PacketWriter.WriteString(Color.SubstituteSpecialColors(listName, useFallbacks), packet.Bytes, 67, hasCP437);
            PacketWriter.WriteString(Color.SubstituteSpecialColors(groupName, useFallbacks), packet.Bytes, 131, hasCP437);
            packet.Bytes[195] = groupRank;
            return(packet);
        }
All Usage Examples Of fCraft.Color::SubstituteSpecialColors