在转档时,标準化很重要,因为没有标準,没有办法做出正常的取代功能。
例底下的4行程式,功能是想同的,但:
标準化的重要性,影响到转档能不能成功,在你要比对资料之前,一定要将某些程式码做一个标準。
例:遇到event.stop=true;整段直接删除
if (ArrayStr[i].indexOf("event.stop=true;") >= 0){ArrayStr[i]="";}
但如果是以下四种状况,要不要删。
event.stop =true; event.stop = true; event.stop= true; event.stop=true;
所以在比对资料之前我会先对程式做一些标準化
str = str.replaceAll("", "");//tab取代为空字串str = str.replaceAll("\"", "'"); //这句是因为TS是用单引号,所以只要遇到双引号,就全部换成单引号str = str.replaceAll(", ", ",");//去除空白str = str.replaceAll(" ,", ",");//去除空白str = str.replaceAll(" =", "=");//去除空白str = str.replaceAll("= ", "=");//去除空白str = str.replaceAll(" =", "=");//去除空白str = str.replaceAll("= ", "=");//去除空白str = str.replaceAll(": ", ":");//去除空白str = str.replaceAll(" :", ":");//去除空白