这样做,长度不同没有问题,你找一些正则表达式的资料看看,用他对字符串处理很方便的。
string="abcdefghijkl"
string2=string.replace(/ghij/,"wert")
alert(string2)