zoukankan      html  css  js  c++  java
  • 字符过滤(petshop 中的)

     
    using System;
    using System.Text;

    namespace PetShop.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();
                
            }

        }

    }

  • 相关阅读:
    Laravel报500错误
    本地部署laravel项目遇到500错误 软链接
    Class 'Maatwebsite\Excel\ExcelServiceProvider' not found
    laravel5.8报500服务器错误
    phpstudy安装redis
    如何在FastAdmin中使用Ajax发送请求?
    关于mysql处理百万级以上的数据时如何提高其查询速度的方法
    判断一个数组里面的所有键所对应的值是否是为int型
    将json字符串中含有非int型的数字字符全部改为int型
    php判断json是否是一个标准的json字符串
  • 原文地址:https://www.cnblogs.com/gwazy/p/153752.html
Copyright © 2011-2022 走看看