⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convertinput.cs

📁 用vs2005写的一个生产任务管理系统。数据的统计和综合查询是主要功能
💻 CS
字号:
using System;
using System.Text;
using System.Text.RegularExpressions;

namespace RWSB.inputcon
{
	/// <summary>
	/// 转换用户的输入。
	/// </summary>
	public sealed class ConvertString
	{

		/// <summary>
		/// 将用户输入的字符串转换为可换行、替换Html编码、无危害数据库特殊字符、去掉首尾空白、的安全方便代码。
		/// </summary>
		/// <param name="inputString">用户输入字符串</param>
		public static string ConvertStr(string inputString)
		{
			string retVal=inputString;
			retVal=retVal.Replace("&","&amp;"); 
			retVal=retVal.Replace("\"","&quot;"); 
			retVal=retVal.Replace("<","&lt;"); 
			retVal=retVal.Replace(">","&gt;"); 
			retVal=retVal.Replace(" ","&nbsp;"); 
			retVal=retVal.Replace("  ","&nbsp;&nbsp;"); 
			retVal=retVal.Replace("\t","&nbsp;&nbsp;");
			retVal=retVal.Replace("\r", "<br>");
			return retVal;
		}

		public static string OutputText(string inputString)
		{
			string retVal=inputString;
			retVal= ConvertStr(retVal);
			retVal=retVal.Replace("[url]", "");
			retVal=retVal.Replace("[/url]", "");
			retVal=retVal.Replace("[img]", "");
			retVal=retVal.Replace("[/img]", "");
			retVal= Regex.Replace(retVal,@"\[flash=\d+,\d+](?<x>[^\]]*)\[/flash]",@"$1",RegexOptions.IgnoreCase);
			retVal=retVal.Replace("[flash]", "");
			retVal=retVal.Replace("[/flash]", "");
			return retVal;
		}

		private static string FetchURL( string strMessage)
		{
			string strPattern = @"(?<url>(http|ftp|mms|rstp|news|https)://(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&~=]*[^.\s|,|\)|<|!])?)";
			string strReplace = "<a href=\"${url}\" target=_blank>${url}</a>";
			string strInput = strMessage;
			string strResult;
			strResult = Regex.Replace(strInput, strPattern, strReplace);
			strPattern = @"(?<!http://)(?<url>www\.(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&~=]*[^.\s|,|\)|<|!])?)";
			strReplace = "<a href=\"http://${url}\" target=_blank>${url}</a>";
			strResult = Regex.Replace(strResult, strPattern, strReplace);
			return strResult;
		} 

		public static string ToUrl(string inputString)
		{
			string retVal=inputString;
			retVal= ConvertStr(retVal);
			retVal= FetchURL(retVal);
			return retVal;
			//retVal= Regex.Replace(retVal,@"\[url](?<x>[^\]]*)\[/url]",@"<a href=""$1"" target=""_blank"">$1</a>",RegexOptions.IgnoreCase);
			//retVal= Regex.Replace(retVal,@"\[flash=(?<width>\d+),(?<height>\d+)](?<x>[^\]]*)\[/flash]",@"<embed src=""$3"" width=""${width}"" height=""${height}""></embed>",RegexOptions.IgnoreCase);
			//retVal= Regex.Replace(retVal,@"\[flash](?<x>[^\]]*)\[/flash]",@"<embed src=""$1""></embed>",RegexOptions.IgnoreCase);
			//return Regex.Replace(retVal,@"\[img](?<x>[^\]]*)\[/img]",@"<a href=""$1"" target=""_blank""><img src=""$1"" onload=""javascript:if(this.width>screen.width-220)this.width=screen.width-220"" border=1></a>",RegexOptions.IgnoreCase);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -