Another elegantIf you do it the following way is to use "Unevaluated" to, applying the C[i]shown rules, since "Unevaluated" works only when it appears and is not propagatedyou get the desired result.
This can be used for all types of equations.
dsol = First@DSolve[y''[x] - 4 y[x] == 1, y, x] /. C[u_] -> Unevaluated[C[u]] (* {y -> Function[{x}, -(1/4) + E^(2 x) C[1] + E^(-2 x) C[2]]} *) sol = First@Solve[{y[0] == a, y'[0] == b} /. dsol, {C[1], C[2]}] (* {C[1] -> 1/8 (1 + 4 a + 2 b), C[2] -> 1/8 + a/2 - b/4} *) ys[x_, a_, b_] = (y[x] /. dsol /. sol) (* -(1/4) + (1/8 + a/2 - b/4) E^(-2 x) + 1/8 (1 + 4 a + 2 b) E^(2 x) *)