📄 chatutils.cs
字号:
// **********************************************************************
//
// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
//
// This copy of Chat Demo is licensed to you under the terms
// described in the CHAT_DEMO_LICENSE file included in this
// distribution.
//
// **********************************************************************
using System;
namespace ChatDemo
{
class ChatUtils
{
public static string formatTimestamp(long timestamp)
{
DateTime date = new DateTime(1970, 1, 1, 0, 0, 0, 0);
date = date.AddMilliseconds(timestamp);
return date.ToLocalTime().ToString("T");
}
public static string formatUsername(string name)
{
try
{
return name.Substring(0, 1).ToUpper() + name.Substring(1, name.Length - 1).ToLower();
}
catch (ArgumentOutOfRangeException)
{
}
return name;
}
public static void validateMessage(string message)
{
if(message.Length > _maxMessageSize)
{
Chat.InvalidMessageException ex = new Chat.InvalidMessageException();
ex.reason = "Message length exceeded, maximum length is " + _maxMessageSize + " characters.";
throw ex;
}
}
public static string stripHtml(string input)
{
var output = "";
for(var cont = 0; cont < input.Length; cont++)
{
switch(input[cont])
{
case '&':
{
output += "&";
break;
}
case '"':
{
output += """;
break;
}
case '\'':
{
output += "'";
break;
}
case '<':
{
output += "<";
break;
}
case '>':
{
output += ">";
break;
}
case '\r':
case '\n':
case '\v':
case '\f':
case '\t':
{
output += " ";
break;
}
default:
{
output += input[cont];
break;
}
}
}
return output;
}
private const int _maxMessageSize = 1024;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -