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

📄 cleanstring.cs

📁 ASP.NET书籍自带的"网上书店销售系统",源码完全公开,没经过封装,都为CS文件,是学习.NET的好参考资料.
💻 CS
字号:
using System;
using System.Text;

namespace BookShop.Web.WebComponents
{
	/// <summary>
	/// A sample class to clean the input into web pages 
	/// </summary>
	public sealed class CleanString {

		public static string InputText(string inputString, int maxLength) {

			
			StringBuilder retVal = new StringBuilder();

			// check incoming parameters for null or blank string
			if ((inputString != null) && (inputString != String.Empty)) {
				inputString = inputString.Trim();

				//chop the string incase the client-side max length
				//fields are bypassed to prevent buffer over-runs
				if (inputString.Length > maxLength)
					inputString = inputString.Substring(0, maxLength);

				//convert some harmful symbols incase the regular
				//expression validators are changed
				for (int i = 0; i < inputString.Length; i++) {
					switch (inputString[i]) {
						case '"':
							retVal.Append("&quot;");
							break;
						case '<':
							retVal.Append("&lt;");
							break;
						case '>':
							retVal.Append("&gt;");
							break;
						default:
							retVal.Append(inputString[i]);
							break;
					}
				}

				// Replace single quotes with white space
				retVal.Replace("'", " ");
			}

			return retVal.ToString();
			
		}
	}
}

⌨️ 快捷键说明

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