zoukankan      html  css  js  c++  java
  • Replace涵數

    sContent為字符串,sPattern為要替換的單引號,sReplexp為替換成雙引號

    function ReplaceString(sContent, sPattern, sReplexp)

    {

            var arrSingle;

            var   sReturnString;

           

    //      split 的工作原理:"as'asdf'asd'''f".split(sPattern)

    //      轉換後會變為[as], [asdf], [asd], [], [], [f]

            if(sContent.length > 0)

            {

                    if(sContent.indexOf(sPattern) >=0)

                    {

                            arrSingle = sContent.split(sPattern);

                            sReturnString = "";

                           

                            //      循環只取第2維到倒數第2.1維與最後1維需要特別處理.

                            for(var i = 1; i< arrSingle.length - 1; i++)

                                    sReturnString += arrSingle[i] + sReplexp;      

                           

                            //      如果第1個字符是Single Quote(單撇號), 則換為Double Quote(雙撇號)

                            if (sContent.indexOf(sPattern) ==0)

                                    sReturnString = sReplexp + sReturnString;

                            else

                                    sReturnString = arrSingle[0] + sReplexp + sReturnString;

                                   

                            // 如果最後1個字符是Single Quote(單撇號), 則換為Double Quote(雙撇號)

                            if (sContent.lastIndexOf(sPattern) != sContent.length - 1)

                                    sReturnString = sReturnString + arrSingle[arrSingle.length - 1];

                           

                            return      sReturnString;  

                    }

                    else

                            return sContent;

            }

            else

                    return sContent;

    }

  • 相关阅读:
    Hibernate关系映射(一) 基于外键的单向一对一
    Hibernate开发环境搭建
    Java创建和读取Json
    Json 简易教程
    jQuery Validate验证框架详解
    asp.net Core 3.1配置log4net
    HTTP 错误 500.21
    SQL中数据库 无法访问,并且数据库的属性中 使用人数、大小、可用空间全是不可用
    What is a CGFloat?
    Swift中的CGPoint ,CGSize 、CGRect、CGFloat
  • 原文地址:https://www.cnblogs.com/guyuehuanhuan/p/1899669.html
Copyright © 2011-2022 走看看