A = {a, b, c, d, e, f, g, h};
B = {1, 2, 3, 4, 5};
pos = {1, 3, 4, 7, 8};
aA = SparseArray[pos -> B];
aA // Normal
(* {1,0,2,3,0,0,4,5} *)
More generally,
(* replace positions # of #3 with #2 and the rest with #4 *)
foo = SparseArray[# -> #2, Length @ #3, #4]&
foo[pos, B, A, 0] //Normal
(* {1, 0, 2, 3, 0, 0, 4, 5} *)
foo[pos, B, A, 100] // Normal (* use 100 instead of 0 as the default element *)
(* {1, 100, 2, 3, 100, 100, 4, 5} *)
foo[{2, 3, 4, 7}, {1, 2, 3, 4}, A, 100] // Normal (* replace any part of A *)
(* {100, 1, 2, 3, 100, 100, 4, 100} *)
Update: Few more alternatives:
ReplacePart[0 A, Thread[pos -> B]]
(* {1, 0, 2, 3, 0, 0, 4, 5} *)
Block[{i = 1}, MapAt[B[[i++]] &, 0 A, List /@ pos]]
(* {1, 0, 2, 3, 0, 0, 4, 5} *)
A. – Igor Rivin Sep 18 '14 at 16:50