Link to home
Start Free TrialLog in
Avatar of gautam_reddyc
gautam_reddyc

asked on

Return empty string containing the number of characters in the length of string

hi ... i have a method which takes empid and returs his year of birth (YOB)- 4 characters...

if the employeeid does not exist it should return the empty string with 4 characters...
how is it possible...
right now it returns empty string- just one blank space..
Avatar of p_davis
p_davis

code please?
if (YOB = "")
{
 return string newyob = "    ";
}
else
{
return YOB;
}

something like that should do if you absolutely need a string with four spaces.
Avatar of gautam_reddyc

ASKER

thanks tsqlguy..

 but it has to give the spaces randomly based on the length of the variable..

say if i want to send my phone number... it should retun the empty string with the ph no. lenght..

Thanks in advance.. Appreciate your help
return new string(' ', YOB.Length);
can i know what is the need of giving spaces, instead of giving a space
ASKER CERTIFIED SOLUTION
Avatar of Jarrod
Jarrod
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW Yoy will notice that i did not initalise Phone number
Any feed back on this code that I sent you ?
Excellent... that worked... thank you...