Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Substring/PARI-GP/substring.parigp
Normal file
23
Task/Substring/PARI-GP/substring.parigp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
\\ Returns the substring of string str specified by the start position s and length n.
|
||||
\\ If n=0 then to the end of str.
|
||||
\\ ssubstr() 3/5/16 aev
|
||||
ssubstr(str,s=1,n=0)={
|
||||
my(vt=Vecsmall(str),ve,vr,vtn=#str,n1);
|
||||
if(vtn==0,return(""));
|
||||
if(s<1||s>vtn,return(str));
|
||||
n1=vtn-s+1; if(n==0,n=n1); if(n>n1,n=n1);
|
||||
ve=vector(n,z,z-1+s); vr=vecextract(vt,ve); return(Strchr(vr));
|
||||
}
|
||||
|
||||
{\\ TEST
|
||||
my(s="ABCDEFG",ns=#s);
|
||||
print(" *** Testing ssubstr():");
|
||||
print("1.",ssubstr(s,2,3));
|
||||
print("2.",ssubstr(s));
|
||||
print("3.",ssubstr(s,,ns-1));
|
||||
print("4.",ssubstr(s,2));
|
||||
print("5.",ssubstr(s,,4));
|
||||
print("6.",ssubstr(s,0,4));
|
||||
print("7.",ssubstr(s,3,7));
|
||||
print("8.|",ssubstr("",1,4),"|");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue