You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

sqr lpad(),rpad() issue

1 reply [Last post]
Guest's picture

Hi All,
Can any one clarify on the below issue
For ex:
Let $str='123wwee'
Let $str1=lpad($str1,4,'0')
show 'String=' $str1
When i execute the above code it is displaying the string value '123wee' with out any changes
but as per the above code it should pad the 0's up to 4 and Final string it should display like
But it is not working as desired
Can any one clarify on this.

Thanks in advance

rahulkhandelw's picture
User offline. Last seen 6 years 45 weeks ago. Offline
Joined: 10/16/2009
Posts: 34
Re: sqr lpad(),rpad() issue

This is happening because the second argument of lpad or rpad specifies length of final string. Here second argument is 4 which is less than the length of $str1. if you want the output as '0000123wwee' than please specify the second argument as 11

Post new comment

The question below is to prevent automated spam submissions.
10 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.