I have a string say message, whose length is not variable. But whatever the length is, I have to add 35 spaces to it before starting another method.
Suggestions Please?
Thanks!
Ex - String = "abc" , should become "abc" + 35 spaces;
No matter what the string is, I need to "Append" 35 spaces to the end of the string.
Use the repeat() method to add a number of spaces to a string, e.g. str + ' '. repeat(3) . The space is repeated the specified number of times and is added to the string.
Fixed-length string is a type of string where length of string is fixed. We are aware of the storage requirement. No matter how many characters constitute the string, the space is fixed. Length of string cannot be changed, once defined.
To add a space between the characters of a string:Use a for...of loop to iterate over the string. Declare an empty string variable. On each iteration, add the character and a space to the string.
To add real spaces to your text, you can use the character entity. Show activity on this post. With template literals, you can use multiple spaces or multi-line strings and string interpolation.
This should do the trick:
message = message.PadRight(message.Length + 35, ' ');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With