3.37 How to find all constants of integration in an expression?

Sometimes I make solution for an ode with constants of integration. These must be of form _Cn where \(n\) is positive integer, such as _C1 or _C5. Now to integrate this solution once more, need to come up with new constant that does not already show in the solution.

To find current constants in an expression use this

sol:=x-_C1*x+_C3*x^2; 
indets(sol,And(symbol, suffixed(_C, nonnegint))); 
 
         {_C1, _C3}
 
Therefore, one way to make a new constant of integration, is to find the largest numbered one and increase by one. Like this
restart; 
sol:=x-_C1*x+_C3*x^2; 
myconstants:=indets(sol,And(symbol, suffixed(_C, nonnegint))); 
map(X->String(X),myconstants); 
map(X->X[3..],%); 
map(X->:-parse(X),%); 
n:=max(%); 
new_constant:=_C||(n+1);