C#在大写字母前删除反斜杠

时间:2016-07-11 02:33:28

标签: c# regex

我试图在大写字母

之前删除一个反斜杠

示例:

字符串之前/G8/W7m/L/K/V/E/X/B/V/L/O/Y/M//W/At1zg==

字符串 之后:G8W7mLKVEXBVLOYM/WAt1zg==

String.replace没有任何帮助,因为它会删除所有反斜杠。

2 个答案:

答案 0 :(得分:1)

使用正则表达式:

var s = "/G8/W7m/L/K/V/E/X/B/V/L/O/Y/M//W/At1zg==";
var result = Regex.Replace(s, @"/(?=[A-Z])", "");

答案 1 :(得分:0)

long hand looks to be working

function remake(){
    var prechange = "/G8/W7m/L/K/V/E/X/B/V/L/O/Y/M//W/At1zg==";
    var postChange = "";

    for (i=0;i<prechange.length;i++){

        if(prechange[i] === "/" ){

            if(prechange[i-1] != undefined && prechange[i-1] != "/" ){
                if(prechange[i+1] == prechange[i+1].toUpperCase() ){
                }else{
                     postChange += prechange[i];
                }
            }else if( prechange[i-1] == "/"  ){
                postChange += prechange[i];
            }

        }else{
            postChange += prechange[i];
        }

    }
    console.log(  prechange + "  " + postChange);

}