C # writes a DLL that reads ISO2709 format data

Source: Internet
Author: User
Tags bool constant definition header tostring
Data

Using System;
Using System.Collections;

/*
The function of this class is to read ISO2709 data
Get ISO2709 data three segments, header \ Catalog \ Data
Get field information
Get child field information
*/

Namespace Nosi.library
{
<summary>
Summary description of the CLASS1.
</summary>
public class Marc
{
#region Constant Definition

Public const char fldend = (char) 30; Field End character
Public const char recend = (char) 29; Record End character
Public const char SUBFLD = (char) 31; Child Field Indicator

public const int Fldname_len = 3; Field name length
public const int Max_marcrec_len = 100000; Max length of Marc Record

#endregion

String m_strmarc = ""; Marc Recording Body

Public Marc ()
{
//
TODO: Add constructor logic here
//
}
Mark
private String GetHeader ()
{
string strheader = null;
Strheader = m_strmarc.substring (0,24);
return strheader;
}
Get the Catalog
private String Getmuci ()
{

char[] Charr = M_strmarc.tochararray ();
string strmuci = null;
int i = 24; Header character no longer read
while (I < m_strmarc.length)
{
Strmuci + = Charr[i]. ToString ();
if (charr[i] = = fldend) break; Discovery Field Identification
i++;
}

return STRMUCI;

}

Get Data area
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;
}

Get the field names in the catalog area
-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)//minus 1 is due to the catalog end identifier
return-1; Length Error

Todo
{
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;
}

Get field contents by field name, number of occurrences in a field
Count starting from 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;
}
Get occurrences of a child field from a field
-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;
}

Get a child field from a field group
-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;
}

 //Get occurrences of the secondary number segment group in the field
 //-1 Error
 //0 not found
 //1 found
&nb Sp 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";//generally distinguished by a child field as a field group
   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;
 }
 //Get character length
 //
  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;
}

}
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.