24小时热门版块排行榜    

Znn3bq.jpeg
查看: 533  |  回复: 6
【奖励】 本帖被评价2次,作者fspdlh增加金币 2
当前主题已经存档。

fspdlh

金虫 (正式写手)


[资源] 【原创】一个自编的读取文本文件数据的函数

如题,自编了一个函数,自已感觉用起来还是很方便的,如有需要可以下载。
    可以读取整个文件,读取第N行,读取第M行到第N行,读取第M行到倒数第N行,读取第M次(也可以是最后一次、倒数第M次)出现字符串str的行开始(或结束)的数据,等等。
以下是自编的帮助文档。
%Get text from file
%
%Input paraments:
%   fid:        filename or the indicater of the file
%   sea_tag:    find the target text from the beginningning of the text or
%               the current position
%       0:  the beginningning of the file   
%       1:  the current position
%   beg profix: paraments to point out the beginning of the output text
%   end profix: paraments to point out the endding of the output text
%   tag:        target string, a string inclued in the target line
%   mode:       the method to match the target line
%       1:  comletely matched
%       2:  beginning matched including blanks
%       3:  beginning matched ignoring blanks
%       4:  included
%   count:      the Nth of the target line
%   offset:     offset from the target line
%       negative ingeger: Nth line before from the target line
%       zero:   the target line
%       positive integer: Nth line followed from the target line
%
%The number of input paraments:
% 1     y=GetFileText(  fid )
% 2     y=GetFileText(  fid,    offset )
% 3     y=GetFileText(  fid,    sea_tag,    offset )
% 4     y=GetFileText(  fid,    sea_tag,    beg_offset, end_offset  )
% 6     y=GetLineText(  fid,    beg_sea_tag,   
%                       beg_str,beg_mode,   beg_count,  beg_offset  )
% 7     y=GetFileText(  fid,    beg_sea_tag,    beg_offset,
%                       end_str,    end_mode,   end_count,  end_offset  )
% 7     y=GetFileText(  fid,    beg_sea_tag,
%                       beg_str,    beg_mode,   beg_count,  beg_offset,
%                       end_offset  )
% 10    y=GetFileText(  fid,    beg_sea_tag,   
%                       beg_str,    beg_mode,   beg_count,  beg_offset,
%                       end_str,    end_mode,   end_count,  end_offset  )

[ Last edited by sunxiao on 2009-3-8 at 13:11 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

fspdlh

金虫 (正式写手)


读取文件的例子

>> type a.txt

01
02
03  01
04
05
06  01
07
08 01
09
10

>> GetFileText('a.txt')

ans =

    '01'
    '02'
    '03  01'
    '04'
    '05'
    '06  01'
    '07'
    '08 01'
    '09'
    '10'

>> GetFileText('a.txt',4)

ans =

04

>> GetFileText('a.txt',0,4,-2)

ans =

    '04'
    '05'
    '06  01'
    '07'
    '08 01'
    '09'

>> GetFileText('a.txt',0,'01',4,1,0)

ans =

01

>> GetFileText('a.txt',0,'01',4,2,0)

ans =

03  01

>> GetFileText('a.txt',0,'01',4,2,-1)

ans =

02

>> GetFileText('a.txt',0,'01',4,2,1)

ans =

04

>> GetFileText('a.txt',0,'01',4,-1,-2)

ans =

06  01

>> GetFileText('a.txt',0,'01',4,-2,0)

ans =

06  01

>> GetFileText('a.txt',0,'01',4,-2,0,-1)

ans =

    '06  01'
    '07'
    '08 01'
    '09'
    '10'

>> GetFileText('a.txt',0,'01',4,1,0,'01',4,-1,0)

ans =

    '01'
    '02'
    '03  01'
    '04'
    '05'
    '06  01'
    '07'
    '08 01'

>> GetFileText('a.txt',0,3,'01',4,3,0)

ans =

    '03  01'
    '04'
    '05'
    '06  01'
    '07'
    '08 01'
2楼2009-03-02 22:43:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

fox-fox

木虫 (知名作家)


下载,试一下
3楼2009-03-03 08:55:18
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

woshilsh

荣誉版主 (职业作家)


★★★★★ 五星级,优秀推荐

鼓励!呵呵!加油!多发布优秀资源
4楼2009-03-03 09:15:06
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xujunqun

银虫 (小有名气)


楼主辛苦
5楼2009-03-26 01:46:35
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

physics206

新虫 (小有名气)


很不错!谢谢楼主分享
7楼2009-04-02 23:47:41
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
简单回复
dnp6楼
2009-03-26 14:37   回复  
 
相关版块跳转 我要订阅楼主 fspdlh 的主题更新
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 面上本子正文33页,违规吗?会被低分嘛? +10 1234567wang 2026-05-17 12/600 2026-05-20 16:48 by metal_D
[论文投稿] Sci. Bull. 悲剧经验 +6 jyang1999 2026-05-16 7/350 2026-05-20 16:39 by feng6531
[基金申请] 提交了我也来说说感想 +5 fummck 2026-05-20 5/250 2026-05-20 15:01 by 六两废铜
[基金申请] 今年审到国自然15份,谈谈感受 +19 国自然国社科中 2026-05-17 20/1000 2026-05-20 14:14 by 仲夏夜的星星
[基金申请] 国自然评分 +3 无名者登山 2026-05-20 4/200 2026-05-20 13:29 by vito刘
[基金申请] 评审有感 +13 popular289 2026-05-18 22/1100 2026-05-20 11:28 by 水和泥不是水泥
[有机交流] 反应很差,大量原料没有反应 5+3 Mr.Zot 2026-05-19 6/300 2026-05-20 10:36 by xtlilibin
[考博] 如果工作了想读博,可以边工作边读全日制嘛? 30+3 铁达火车 2026-05-18 5/250 2026-05-20 09:33 by tfang
[基金申请] 河北省自然科学基金 +3 Peterchao 2026-05-18 3/150 2026-05-20 08:57 by 霸_霸
[教师之家] 上海大学实验技术岗位非升即走 +12 嘻嘻哈哈乐呵呵 2026-05-15 13/650 2026-05-20 08:34 by xli1984
[考博] 云南大学材料与能源学院解琳课题组钙钛矿博士招生 +3 光伏爱好者 2026-05-17 5/250 2026-05-19 19:13 by 光伏爱好者
[考博] 找博士生导师 +6 小代想上岸 2026-05-15 7/350 2026-05-19 10:22 by free_fisher
[基金申请] 同样的基金本子,换个专家直接从C变A! (金币-10) +3 国自然国社科中 2026-05-19 3/150 2026-05-19 08:50 by Equinoxhua
[考博] 2026博士还有哪些学校有名额 +7 小王求读研 2026-05-15 8/400 2026-05-19 08:27 by zhyzzh
[基金申请] 国自然上会要求 +5 无名者登山 2026-05-18 9/450 2026-05-18 17:50 by BlakeReary
[硕博家园] 我在等一个没有答案的答案 +3 Love_MH 2026-05-17 3/150 2026-05-18 02:22 by 竹林孤影
[文学芳草园] 半夜喝咖啡 +3 myrtle 2026-05-15 5/250 2026-05-18 01:03 by 小沈2018
[考博] 光量子物理方向 博士招生 1人(2026.09) +3 sandyworld 2026-05-15 4/200 2026-05-17 14:38 by sandyworld
[硕博家园] 申请博士 +3 呃?呃 2026-05-15 3/150 2026-05-16 11:01 by a4742549
[考博] 26应届毕业生考博求助 +3 wo一定上岸 2026-05-13 3/150 2026-05-14 21:47 by 明海天涯
信息提示
请填处理意见