cino hilliard on Thu, 22 Jan 2004 01:07:28 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
String utilities/files |
Hi,Thanks Karim for the Strchr function I notice in the last release of the windows pari.exe I have built some traditional string functions using this and others. See the script below. See my comments. I have loaded this in my .gprc file but it would be nice if this would be built in to Pari in
optimized code. There are many more functions that could be added.Also it would be nice to be able to do more direct file handling in Pari. I want to be able to read
a 20 or 30 gig file of prime numbers. Maybe someone can help me do a DLL for windows? \\strutil.gp \\ This file should be in the working directory \\ add read "strutil" to the .gprc file \\ String utilities (Thanks to StrChr in latest version)\\ However the pari ascii set is different from the dos set. Eg., code 227 = symbol
\\ for pi in dos. Here we get a. \\ Enclose str,chr, in "" to avoid errors. \\ You have to use kill to clear the variable if you don't use the "". \\ Define the Pari ascii table ascii=vector(255);for(x=1,255,ascii[x]=Strchr(x)); \\ Get the Pari ascii code of a character. asc(chr) = { setsearch(ascii,chr) }\\ Get a substring of length n from string str starting at position s in str.
mid(str,s,n) = { v =""; tmp = Vec(str); ln=length(tmp); if(!s,s=1); if(!n,n=ln-s+1); if(n>ln,n=ln-s); for(x=s,s+n-1, v=concat(v,tmp[x]); ); return(v) } \\ Get the left n characters from string str. left(str,n) = { v =""; tmp = Vec(str); ln=length(tmp); if(n > ln,n=ln); for(x=1,n, v=concat(v,tmp[x]); ); return(v) } \\ Get the right n characters from string str. right(str,n) = { v =""; tmp = Vec(str); ln=length(tmp); if(n > ln,n=ln); s = ln-n+1; for(x=s,ln, v=concat(v,tmp[x]); ); return(v) } \\ Get the position of occurrence of m string in string str. instr(str,match) = { tmp=Vec(str); tmp=Set(tmp); m=Vec(match); ch=m[1]; \\ ch=left(match,1); won't work. x=setsearch(tmp,ch); return(x) } Cino "Behavior is not for the pursuit of survival but because of it." _________________________________________________________________Rethink your business approach for the new year with the helpful tips here. http://special.msn.com/bcentral/prep04.armx