我想把一个字符串特定位置的一个字符改写成’-',
我试了replace但是发现无法指定位置,所以我还是用的字符串拼接的方式
using BenchmarkTools
str="Y--ZZ-y--ZZ-ZZZ------Y------------x-zZZ-ZZ-ZZ-z-ZZY--Z----------"
function replacing(str,location)
return SubString(str,1,location-1)*'-'*SubString(str,location+1)
end
julia> @btime replacing(str,35)
71.939 ns (3 allocations: 160 bytes)
"Y--ZZ-y--ZZ-ZZZ------Y--------------zZZ-ZZ-ZZ-z-ZZY--Z----------"
各位大佬还有其他方式么?