Remove function?

seany seany at uni-bonn.de
Wed Dec 4 14:33:04 PST 2013


On Wednesday, 4 December 2013 at 22:14:18 UTC, Ali Çehreli wrote:
> On 12/04/2013 01:59 PM, seany wrote:
>> Hello, I want to remove a car form a string.
>>
>> hence i used the remove function from std.algorithm, and i had 
>> this :
>>
>> string stripPar(string S)
>> {
>>     while(S[0] == '(' && S[S.length-1] == ')')
>>     {
>>
>>          S = S.remove(0);
>>          S = S.remove(S.length-1);
>>     }
>>
>>     return S;
>>
>
> A shorter alternative:
>
> import std.algorithm;
>
> string stripPar(string S)
> {
>     return S.stripLeft('(').stripRight(')');
> }
>
> Ali

that works, but wont the immutability imply that the above 
solution shall not work?


More information about the Digitalmars-d-learn mailing list