adding spaces to string

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

I'd like to add several spaces to a string variable. For example, if the
value is "VM", I'd like to add 7 spaces so the new value is "VM ".

Is that possible?
Thanks.
 
Of course it's possible.

Are you having trouble with the obvious:

string s1 = "VM";

s1 = s1 + " ";

~ or ~

string s1 = "VM";
string s2 = s1 + " ";


HTH
Brian W
 
VM said:
I'd like to add several spaces to a string variable. For example, if the
value is "VM", I'd like to add 7 spaces so the new value is "VM ".


Hi VM,

You can use the string type's PadRight() method.

Joe
 
Hi VM,
You cannot modify strings. They are immutable. You can only set a varable of
type "string" to reference different String object. Means that if you have
more than one string variable referencing the same string you have to change
all of them.

However, cack out String.PadRight method and StringBuilder class.
Bear in mind that they return different string objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top