473,485 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

adding spaces to string

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.
Nov 15 '05 #1
8 22572
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" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 15 '05 #2
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" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 15 '05 #3
"VM" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
--
http://www.csharp-station.com
Nov 15 '05 #4
"VM" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
--
http://www.csharp-station.com
Nov 15 '05 #5
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.

--
B\rgds
100

"VM" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 15 '05 #6
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.

--
B\rgds
100

"VM" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 15 '05 #7
Try this:

string s = "VM";
string s = s + new String(' ', 7);

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"VM" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 15 '05 #8
Try this:

string s = "VM";
string s = s + new String(' ', 7);

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"VM" <vo******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1667
by: Papajo | last post by:
Is there a script that would add a space in front of and behind any text adding to a form box, it coud be triggered by either an onClick or onBlur event handler. Any help s appreciated. Thanks Joe
0
965
by: VM | last post by:
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.
3
1345
by: TomislaW | last post by:
Is it possible to add query string on requested page e.a. i have request for index.aspx, but i need index.aspx?language=en is this possible tomislaw
1
2182
by: MaRkHaSBEEnMade | last post by:
Hi there I currently have a listbox that displays provinces,regions and suburbs.I want to pad the items logically with spaces,but the spaces are being igonred... eg Province1 ...
2
8719
by: John Dann | last post by:
I have a standard .Net DateTime variable to which I want to add a time value. The catch is that the time value is only readily available as a string as "HH:mm". Question is whether there's a...
5
4139
by: Steve | last post by:
I'm getting string returned from my Database with a space in front of it, it sometimes it looks like this 8 9 10 1 and so one, how can I remove the white space in front of the numbers? Its...
1
1571
by: theflyingminstrel | last post by:
Does anyone know how I might add a function to this script that continually adds one space before and after the entire query (not in between every word though)? Example: If I type in the...
6
5401
by: Spikey | last post by:
Hi, I have a problem that's (probably) very easy to solve, only I'am more a Java programmer and I couldn't find anything like it on the internet. My problem is that I have to add a variable (int,...
8
4721
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
7090
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7116
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6825
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7275
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5418
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4857
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1376
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.