Remove function?
Ali Çehreli
acehreli at yahoo.com
Wed Dec 4 14:14:18 PST 2013
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
More information about the Digitalmars-d-learn
mailing list