By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

string

P: 38
Hi all,

how can i add a variable number of spaces in string,

for example:
Expand|Select|Wrap|Line Numbers
  1. int i (7);
  2. string st1 = "example1";
  3. string st2 = "example2"
  4. st1 +=  "      ";  ?? what i ve to write to get the number of spaces prameterized??
  5. st1 += st2  // outpot --  example1      example
  6.  

how can i declare the number of desired space in string ??

thank a lot...
Sep 12 '09 #1
Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Create another string with the correct number of spaces and append that string to st1.
Sep 12 '09 #2

P: 38
this solution will not help me...

Actually, the number of sapces i have to calulate in the programm, so sometimes 8 space tabs anothertime 20, it depends on code.

Now, i want to change this number of spaces (8,..., 20) as a string (" " or " ") and so on...


thank for each advance..
Sep 12 '09 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
Of course my suggestion will work:

Write a function that returns a string. Inside the function calculate the number of spaces and build a string that long. Return that string.

Then append the string the function returns to st1.
Sep 12 '09 #4

P: 38
you are right.... but exactly, that is my question? how can i build a string that long??

thanks for each advice
Sep 12 '09 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
Calculate the number of spaces. Say, 28. Then run a loop 28 times that appends one space to a newly created string.
Sep 12 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.