Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
? substr(s,n,m)=concat(Vec(s)[n..n+m-1]) %1 = (s,n,m)->concat(Vec(s)[n..n+m-1]) ? s="h0getcwdfailedNosuchfileordirectory" %2 = "h0getcwdfailedNosuchfileordirectory" ? substr(s,4,8) %3 = "etcwdfai"
问题:有没有更好的方法(内置函数?)在 PARI/gp 中获取子字符串?
并不真地。这是一个更快的hack(也使用更少的内存)
substr2(s,n,m)=strchr(Vecsmall(s)[n..n+m-1])
在您的示例中计时:
? substr2(s,4,8) %1 = "etcwdfai" ? for(i=1,10^6,substr(s,4,8)) time = 536 ms. ? for(i=1,10^6,substr2(s,4,8)) time = 266 ms.