惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - fisherman

学习写第一个SQL server触发器 操纵自如--页面内的配合与通信 一些DIV+CSS 命名规范 asp.net 2.0中生成RSS 避免重复提交 - fisherman - 博客园 button 删除确认 - fisherman - 博客园 用相对定位和负向移动完成图片象框阴影 负边距居中法(水平居中、垂直居中) - fisherman - 博客园 CSS 代码格式化工具 - fisherman - 博客园 JS代码的格式化和压缩 - fisherman - 博客园 把SQL SERVER里表里的数据导出成为insert into 脚本 对FckEditor编辑器在MAXTHON浏览器下选择服务器文件对话框显示不正常的改进 下载网页中远程图片的方法 读取marc数据 关于ISO2709数据的格式说明 数据库打开 使用 Engine 对象创建 SQL Server Compact Edition 数据库 用SharpZipLib压缩和解压缩文件 Access数据库压缩和修复
C#写的读取ISO2709格式数据的DLL
fisherman · 2007-07-04 · via 博客园 - fisherman

using System;
using System.Collections;

/*
此类的功能,是读取ISO2709数据
得到ISO2709数据三个段,头标目次数据
获得字段信息
获得子字段信息
 
*/


namespace Nosi.Library
{
 
/// <summary>
 
/// Class1 的摘要说明。
 
/// </summary>

 public class Marc
 
{
  
常量定义

  
string m_strMarc = ""// MARC记录体

  
public Marc()
  
{
   
//
   
// TODO: 在此处添加构造函数逻辑
   
//
  }

  
//获得头标
  private string GetHeader()
  
{
   
string strHeader = null;
   strHeader 
= m_strMarc.Substring(0,24);
   
return strHeader;
  }

  
//获得目次
  private string GetMuci()
  
{
   
   
char[] charr = m_strMarc.ToCharArray();
   
string strMuci = null;
   
int i = 24// 头标字符不再读取
   while(i < m_strMarc.Length)
   
{
    strMuci 
+= charr[i].ToString();
    
if(charr[i] == FLDEND) break;  //发现字段标识
    i++;
   }


   
return strMuci;

  }


  
// 获得数据区
  private string GetData()
  
{
   
string strData = null;
   
int iMuci = this.GetMuci().Length;
   
int iHeader = this.GetHeader().Length;
   
int iMarc = m_strMarc.Length;
   strData 
= m_strMarc.Substring(iMuci + iHeader,iMarc - iMuci - iHeader);
   
return strData;
  }


  
// 获得目次区中的字段名
  
//  -1 error
  
//  0  no found
  
//  1  found
  private  int GetFieldPos(string strFieldName,
   
int nIndex,
   
out string  strFieldPos)
  
{
   
string strMuci = this.GetMuci();
   strFieldPos 
= null;
   
   
int i = 0;
   
int nRet = 0;

   
if(strMuci == null)
    
return -1;

   
   
if((strMuci.Length - 1% 12  != 0// 减1是由于目次区结束标识符
    return -1// length error

   
do
   
{
    
if(strMuci.Substring(i,3== strFieldName)
     nRet 
++;
    
if(nRet == nIndex)// from zero add
    {
     strFieldPos 
= strMuci.Substring(i,12);
     
break;
    }

    i 
+= 12;
   }
 while(i<strMuci.Length);

   
if (strFieldPos  == null
   
    
return 0// no found 
   
  
   
return 1;
  }


  
// 通过字段名,字段中出现次数获得字段内容
  
// 次数从 1  开始计数
  
// -1 error
  
// 0  no found
  
// 1  found
  public int GetField(string strFldName,
   
int nIndex,
   
out string strFld)
  
{
   strFld 
= null;
   
   
string strFldPos = null;
   
int nRet = this.GetFieldPos(strFldName,nIndex,out strFldPos);
   
if (nRet != 1)
    
return nRet;
   
if(strFldName.Length != 3 )
    
return -1;  // subfield must 3 chars 
   
   
int nLength = int.Parse( strFldPos.Substring(3,4));
   
int nBeginPos = int.Parse( strFldPos.Substring(7,5));
   
char[] chData = this.GetData().ToCharArray();
   
int nPos =0;
   
int i = 0;
   
while( nPos < chData.Length)
   
{
    i 
+= GetCharLength(chData[nPos]);
    
if((i >= nBeginPos) && i<= (nBeginPos + nLength))
     strFld 
+= chData[nPos].ToString();
    nPos 
++;

   }

   
if(strFld == null)
    
return 0;
   
return 1;
  }

  
//从字段中获得出现次数的子字段
  
// -1 error
  
// 0 not found
  
// 1 found
  public int GetSubField(string strFld,
   
string  strSubName,
   
int nIndex,
   
out string strSubFld)
  
{
   strSubFld  
= null;
   
if(strSubName.Length != 1
    
return -1// subfield'symbol char must 1 char
   if(strFld == null)
    
return -1;
   
   
char[] chData = strFld.ToCharArray();
   
int nPos = 0;
   
bool isNewSub = false;
   
int nFound = 0// 0: not 1: first time found 2: second time found
   while( nPos < chData.Length)
   
{    
    nPos 
++
 
    
if((chData[nPos-1== SUBFLD) && (chData[nPos].ToString() == strSubName))
     nFound 
++// found    

    
if ((nFound == nIndex) && (isNewSub == false))
    
{     
     
if(chData[nPos] == SUBFLD)
     
{
      isNewSub 
= true;
      
break;
     }

     strSubFld 
+= chData[nPos].ToString();
    }


   }

   
if(strSubFld == null)
    
return 0;
   
return 1;
  }


  
//从字段组中获得子字段
  
// -1 error
  
// 0 not found
  
// 1 found
  public int GetSubField(string strGroup,
   
string  strSubName,
   
out string strSubFld)
  
{
   strSubFld  
= null;
   
if(strSubName.Length != 1
    
return -1// subfield'symbol char must 1 char
   if(strGroup == null)
    
return -1;
   
   
char[] chData = strGroup.ToCharArray();
   
int nPos = 0;
   
bool isNewSub = false;
   
int nFound = 0// 0: not 1: first time found 2: second time found
   while( nPos < chData.Length)
   
{    
    nPos 
++
 
    
if((chData[nPos-1== SUBFLD) && (chData[nPos].ToString() == strSubName))
     nFound 
++// found    

    
if (isNewSub == false)
    
{     
     
if(chData[nPos] == SUBFLD)
     
{
      isNewSub 
= true;
      
break;
     }

     strSubFld 
+= chData[nPos].ToString();
    }


   }

   
if(strSubFld == null)
    
return 0;
   
return 1;
  }


  
//从字段中获得出现次数字段组
  
// -1 error
  
// 0 not found
  
// 1 found
  public int GetFieldGroup(string strFld,
   
int nIndex,
   
out string strGroup)
  
{
   strGroup 
= null;
   
   
if(strFld == null)
    
return -1;
   
   
char[] chData = strFld.ToCharArray();
   
int nPos = 0;
   
string strSplit = "a"// 一般以a子字段为字段组区分 
   int nFound = 0// 0: not 1: first time found 2: second time found
   while( nPos < chData.Length)
   
{    
    nPos 
++
 
    
if((chData[nPos-1== SUBFLD) && (chData[nPos].ToString() == strSplit))
     nFound 
++// found    

    
if (nFound == nIndex)
     strGroup 
+= chData[nPos].ToString();
    
if(nFound > nIndex)
     
break;    
   }

   
if(strGroup == null)
    
return 0;
   
return 1;
  }

  
//获得字符的长度
  
//
  private int GetCharLength(char ch)
  
{
   
int nLength = 0;
   
   
if((short)ch < 0 || (short)ch  > 128)
   
{
    nLength 
+= 2;
   }

   
else 
   
{
    nLength 
= nLength + 1;
   }

   
return nLength;
  }


  
public string strMarc
  
{
   
get 
   
{
    
return m_strMarc;
   }

   
set 
   
{
    m_strMarc 
= value;
   }


  }

 }

}


来源:
http://www.chengxu123.cn/detailt_54111.html