Click here to Skip to main content
15,895,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello!
These are my strings;
C#
str1=(_averagekids + "/-").ToString().PadRight(7));
str2=(_averageadults + "/-").ToString().PadRight(7));

when i run the code it is correct for the output:
600/-
45/-
but wrong for output:
1100/-
 45/-

cant get ,whats going on? thanks in advance
Posted
Updated 6-Oct-13 19:45pm
v3
Comments
tanweer 7-Oct-13 1:40am    
Hi, PadRight is used to return string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character. what do you want here, what is the value of _averagekids and _averageadults in your code?
Zubair SE 7-Oct-13 1:51am    
it is double and is set in string varaiable
tanweer 7-Oct-13 1:55am    
I mean do you want just to add "/-" at the end of that string?
Zubair SE 7-Oct-13 2:06am    
Yes
((_averagekids + "/-").ToString()).PadLeft(7));
Zubair SE 7-Oct-13 2:08am    
i have to get printout of it on a slip

Hi, try the below code, this should work for you, it will add padd after the string
C#
str1=(_averagekids + "/-").ToString().PadRight(7, ' '));
str2=(_averageadults + "/-").ToString().PadRight(7, ' '));
 
Share this answer
 
i found solution , it is working only with
str1=((_averagekids + "/-").Trim().ToString()).PadLeft(7));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900