I’m trying to add a character many times before a string. AMAIK in C#, it’s PadLeft.
string firstName = "Mary";
firstName = firstName.PadLeft(3, '*'); // This should return ***Mary
But it doesn’t work. Am I doing something wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first argument is total length of the returned string, as "Mary" is 4 characters long and your first argument is 3, it is working as expected. If you try
firstName.PadLeft(6, '*')you’ll get **Mary.