I've done it once using:
mat = RandomReal[1, {100, 100}];
newmat = mat - DiagonalMatrix[Diagonal[mat]];
keeps it packed if mat is packed, it is short and reasonably legible... Of course this does do n^2 operations while only n are necessary...
But I see other options:
mat=RandomReal[1,{10,10}];
RepeatedTiming[newmat=mat-DiagonalMatrix[Diagonal[mat]];]
RepeatedTiming[newmat2=mat(1-IdentityMatrix[Length[mat]]);]
RepeatedTiming[newmat3=ReplacePart[mat,Array[{#,#}&,Length[mat]]->0.0];]
RepeatedTiming[newmat4=(tmp=mat;Do[tmp[[i,i]]=0.0,{i,Length[tmp]}];tmp);]
newmat==newmat2==newmat3==newmat4
or with integers:
mat=RandomInteger[100,{10,10}];
RepeatedTiming[newmat=mat-DiagonalMatrix[Diagonal[mat]];]
RepeatedTiming[newmat2=mat(1-IdentityMatrix[Length[mat]]);]
RepeatedTiming[newmat3=ReplacePart[mat,Array[{#,#}&,Length[mat]]->0];]
RepeatedTiming[newmat4=(tmp=mat;Do[tmp[[i,i]]=0,{i,Length[tmp]}];tmp);]
newmat==newmat2==newmat3==newmat4
depending on the size of the matrix and the contents (partially symbolic, or packed or ...) one might be faster than the other.
Any idea about the name of the function and the implementation? I see several ways:
newmat = SetDiagonal[mat, a]
where a is a single element or a list.
or a Span-kinda implementation:
mat[[{1,1};;]] = 0
Where we now iterate (like a span) over 2 things at the same time. but might be a bit too confusing syntax. Another symbol (like span) is also possible of course:
mat[[Diagonal[k]]] = 0
where k must be in integer such as to not destroy Diagonal functionality, it merely acts as a wrapper...