对所有.mfps文件,文首,文尾批量加相同的文字
mfp吧
全部回复
仅看楼主
level 13
variable path="/storage/emulated/0/AnMath/scripts/TXT"
list_files(path)
//sleep(6000)
for variable k=0 to size(ans)[0]-1
if(strsub(ans[k],strlen(ans[k])-5,strlen(ans[k]))==".mfps")
list_files(ans[k])
endif
next
//sleep(6000)
for variable k=0 to size(ans)[0]-1
variable fo=fopen("/storage/emulated/0/AnMath/scripts/TXT/"+ans[k],"r","utf_8")
variable fo1=fopen("/storage/emulated/0/AnMath/scripts/TXT*/"+ans[k],"w","utf_8")
fprintf(fo1,"%s\n\n","citingspace::{myfunc}")
do
variable st=freadline(fo)
fprintf(fo1,"%s\n",st)
until(feof(fo))
fprintf(fo1,"\n%s","endcs")
fclose(fo1)
fclose(fo)
next
return
2016年08月16日 10点08分 1
level 13
[疑问]哪里错了[泪]
2016年08月16日 13点08分 4
错误在哪里?
2016年08月16日 13点08分
@woshiwppaa 能不用弄个缓存数组来代替ans值?我试过先将list_file(path)数据存入文件中,再调用该文件的数据代替ans数组进行下一步计算。或者对ans进行数组申明,需要时对ans[x]进行调用,但ans只能对上一操作答案记录。
2016年08月16日 14点08分
level 13
为什么分开执行时可以呢?
2016年08月16日 13点08分 5
你自己建一个缓存数组,把结果保存在里面,如何
2016年08月16日 20点08分
level 13
function f_xj(s)//新建文件
return create_file(s)
endf
function f_qk(s)//清空文字内容
variablefe = fopen(s, "w","UTF-8")
fprintf(fe,"%s","")
fclose(fe)
endf
function f_storage_f(s,str)
variable fp=fopen(s,"a","UTF-8")
fprintf(fp,"%s\n",str)
fclose(fp)
endf
2016年08月16日 22点08分 9
level 13
help
@language:simplified_chinese
//例variable path="/storage/emulated/0/AnMath/scripts/TXT" ⇒原.mfps所在<文件夹>路径
//例variable new_path="/storage/emulated/0/AnMath/scripts/TXT_new" ⇒新.mfps所在<文件夹>路径
//例variable csname="myf"
//添加空间名如"myf"或"myf::f"
@end
endh
function f_mfps_aedit(path,new_path,csname)
if(ls("temp")==1)
f_qk("temp")
else
f_xj("temp")
endif
variable list=list_files(path)
for variable k=0 to size(list)[0]-1
if(strsub(list[k],strlen(list[k])-5,strlen(list[k]))==".mfps")
f_storage_f("temp",list[k])
endif
next
variable fp=fopen("temp","r","utf_8")
do
variable str=freadline(fp)
variable fo=fopen(path+"/"+str,"r","utf_8")
variable fo1=fopen(new_path+"/"+str,"w","utf_8")
//fprintf(fo1,"%s\n\n","citingspace ::func")
fprintf(fo1,"%s\n\n","citingspace ::"+csname)
do
variable st=freadline(fo)
fprintf(fo1,"%s\n",st)
until(feof(fo))
fprintf(fo1,"\n%s","endcs")
fclose(fo1)
fclose(fo)
until(feof(fp))
fclose(fp)
//f_gm(new_path,path)
endf
2016年08月17日 01点08分 12
function f_gm(s,t)//改名文件 copy_file(s,t) delete_file(s,true) endf
2016年08月17日 03点08分
level 13
2016年08月18日 07点08分 15
level 13
function f_add_hh(rp,ap)
if(ls(ap)==1)
f_qk(ap)
else
f_xj(ap)
endif
variable fa=fopen(ap,"a","utf_8")
variable fr=fopen(rp,"r","utf_8")
variable k=0
do
k=k+1
variable str=freadline(fr)
if(and(str!="",strsub(str,0,2)!="//"))
fprintf(fa,"%s\n",str+" //☞第"+k)
elseif(and(str!="",strsub(str,0,2)=="//"))
fprintf(fa,"%s\n",str+" ☞第"+k)
endif
until(feof(fr))
fclose(fr)
fclose(fa)
//f_gm(ap,rp)
endf
2016年08月18日 07点08分 16
level 13
[疑问]如果,文加行号_new.mfps中出错了,要增加或减少行数,怎样将"//第1"这样的文字去掉,重新编排,加行数[疑问]
2016年08月18日 08点08分 17
将图中 文加行号_new.mfps改回到图中 文加行号.mfps这种格式[疑问]
2016年08月18日 08点08分
level 13
有三种格式需变动,
①第21行:文尾去掉 "☞第21"
②第1~9行:文尾去掉"//☞第1"~"//☞第9"
③第10~20行及第22行:文尾去掉"//☞第10"~"//☞第20"及"//☞第22"
①中无"//"
②③字符长度不同
得用3个if
2016年08月18日 08点08分 18
行首有"//"⇒if <1>,保留行肯"//",去掉行尾"第"及其后所有字符。 行尾部有"//"⇒if <2>,去掉"//"及其后所有字符。
2016年08月18日 08点08分
level 13
if <1>//☞第21
variable h=split(str,"☞")
取h[0]
elseif <2>//第1~20,第22
variable g=split(str,"//")
取g[0]
endif
2016年08月18日 08点08分 19
level 13
2016年08月18日 09点08分 20
level 13
function f_delete_hh(rp,ap)
if(ls(ap)==1)
f_qk(ap)
else
f_xj(ap)
endif
variable fa=fopen(ap,"a","utf_8")
variable fr=fopen(rp,"r","utf_8")
variable k=0
do
k=k+1
variable str=freadline(fr)
if(and(str!="",strsub(str,0,2)!="//"))
fprintf(fa,"%s\n",split(str," //")[0])
elseif(and(str!="",strsub(str,0,2)=="//"))
fprintf(fa,"%s\n",split(str," ☞")[0])
endif
until(feof(fr))
fclose(fr)
fclose(fa)
//f_gm(ap,rp)
endf
2016年08月18日 11点08分 21
f_delete_hh与f_add_hh可以整合到一个程序中如:f_edit_hh(rp,ap,<1>)⇒f_add_hh f_edit_hh(rp,ap,<2>)⇒f_delete_hh 通过case或if语句将两程序中split和*…加以区分,相同部分予以保留
2016年08月20日 00点08分
level 13
据目录选择打开文档
help
@language:simplified_chinese
f_mulu_r(path,hzui)
例如:
f_mulu_r("/storage/sdcard1/Books",".txt")
endh
//主程序:打开文件夹,显示目录,选择并打开文件
function f_mulu_r(path,hzui)
//variable path="/storage/sdcard1/Books"
//variable hzui=".txt" or ".mfps"
if(ls("tem")==1)
f_qk("tem")
else
f_xj("tem")
endif
variable list=list_files(path)
variable k=0
do
k=k+1
if(strsub(list[k-1],strlen(list[k-1])-strlen(hzui),strlen(list[k-1]))==hzui)
f_storage_f("tem",list[k-1])
endif
until(k==size(list)[0])
f_add_hh("tem","temp")
variable fp=fopen("temp","r","utf_8")
do
variable str=freadline(fp)
printf("%s\n",str)
until(feof(fp))
fclose(fp)
pause("\n回车键继续…")
variable h=input("\n?(hh),(u or g):","s")
variable hh=split(h,",")[0]
variable sm=split(h,",")[1]
variable encoding=iff(sm=="u","utf_8",sm=="g","gbk","")
variable fp1=fopen("temp","r","utf_8")
do
variable t=split(freadline(fp1)," //☞第")
if(t[1]==hh)
f_xst(path+"/"+t[0],encoding)
endif
until(feof(fp1))
fclose(fp1)
endf
2016年08月19日 05点08分 22
level 13
//相关子程序:显示文本内容
function f_xst(s,p)
variable fp=fopen(s,"r",p)
print("☞{当前的文本是:"+s+"}\n")
variable k=0
do
k=k+1
variable str=freadline(fp)
print("№"+k+":📖"+str)
//pause("\n回车键继续…")
pause("")//无需提示,直接回车键
until(feof(fp))
fclose(fp)
endf
//相关子程序:存储文件
function f_storage_f(s,str)
variable fp=fopen(s,"a","UTF-8")
fprintf(fp,"%s\n",str)
fclose(fp)
endf
//相关子程序:新建文件
function f_xj(s)
return create_file(s)
endf
//相关子程序:清空文字内容
function f_qk(s)
variablefe = fopen(s, "w","UTF-8")
fprintf(fe,"%s","")
fclose(fe)
endf
//相关子程序:段尾填加行号
function f_add_hh(rp,ap)
if(ls(ap)==1)
f_qk(ap)
else
f_xj(ap)
endif
variable fa=fopen(ap,"a","utf_8")
variable fr=fopen(rp,"r","utf_8")
variable k=0
do
k=k+1
variable str=freadline(fr)
if(and(str!="",strsub(str,0,2)!="//"))
fprintf(fa,"%s\n",str+" //☞第"+k)
elseif(and(str!="",strsub(str,0,2)=="//"))
fprintf(fa,"%s\n",str+" ☞第"+k)
endif
until(feof(fr))
fclose(fr)
fclose(fa)
endf
2016年08月19日 06点08分 24
level 13
//改进显示内容,增加退出命令
function f_xst(s,p)
variable fp=fopen(s,"r",p)
print("☞{当前的文本是:"+s+"}\n")
variable k=0
do
k=k+1
variable str=freadline(fp)
print("№"+k+":📖"+str)
variable w=input("\n☞","s")
//无输入换行继续,输入其它终止
if(w!="")
break
else
continue
endif
until(feof(fp))
fclose(fp)
endf
2016年08月19日 07点08分 25
如果在暂停☞处,用if(w==)句调用其它子程序,如:f_jsb_a(,),启用记事本功能。记录此处行号,再编辑个程序,读取记录打开文档,然后继续从此处阅读。
2016年08月19日 11点08分
以前读过的段不再显示,怎样才能实现从文本的任意某一段开始阅读(标签功能)点出标签,调用文本。
2016年08月19日 12点08分
1 2 尾页