Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a fixed number of spaces to the end of a variable length string

Tags:

c#

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.

like image 275
Kimi Avatar asked Nov 02 '12 20:11

Kimi


People also ask

How to add number of spaces in a string java?

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.

What is a fixed-length 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.

How do you add a space in a string?

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.

How to insert a space in a string javascript?

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.


1 Answers

This should do the trick:

message = message.PadRight(message.Length + 35, ' ');
like image 146
Mike Perrenoud Avatar answered Nov 14 '22 08:11

Mike Perrenoud