Check if this example works with empty and non-empty segments:
string old_string = "Segment Details~Anixter~~NBM~~1~HQ";
int position = 2;
string new_value = "SomeCode";
var a = old_string.Split( '~' );
string new_string = string.Join( "~", a.Take( position ).Append( new_value ).Concat( a.Skip( position + 1 ) ) );
Console.WriteLine( old_string );
Console.WriteLine( new_string );