In C#, String.PadLeft does the same for you.
You can just trim the string and apply padding.
string accountNo = "123321 ";
string result = accountNo.Trim().PadLeft(15, ' ');
------------------------------
output:
123321
For more details,
click here[
^]