• 字符过滤(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();
                
            }

        }

    }

  • 相关阅读:
    20220530复盘
    20220524复盘
    20220523复盘
    20220520复盘
    22020527复盘
    sys模块
    mongodb安装部署
    weblogic12c安装部署
    python字符串操作
    pythonpyttsx3模块
  • 原文地址:https://www.cnblogs.com/gwazy/p/153752.html
Copyright © 2020-2023  润新知