通过对目次地址区的分析从数据区读取希望得到的数据
此方法可以读取iso格式的marc和txt格式的marc
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/// <summary>
/// 获取数据
/// </summary>
/// <param name="record">marc数据</param>
/// <param name="chNum">字段号</param>
/// <param name="subField">子字段号</param>
/// <returns>得到的值</returns>
public string GetContent(string record,string chNum,string subField)
{
string strDataContent = string.Empty ;
string dataZone;
string[,] splitedMuci;
int loc;
int startLoc;
int len;
loc = record.IndexOf('@');
dataZone = record.Substring(loc + 1);
splitedMuci = SplitMuciZone(record);
for (int i = 0; i < splitedMuci.Length / 3; i++)
{
if (splitedMuci[i, 0] == chNum)
{
startLoc = int.Parse(splitedMuci[i, 2]) - GetOffSet(dataZone, 0, int.Parse(splitedMuci[i, 2]));
len = int.Parse(splitedMuci[i, 1]) - GetOffSet(dataZone, int.Parse(splitedMuci[i, 2]), startLoc + int.Parse(splitedMuci[i, 1]));
strDataContent = dataZone.Substring(startLoc, len - 1);
}
}
if (subField == "")
{
return strDataContent;
}
else
{
string[] subData = strDataContent.Split('$');
for(int i = 1;i<subData.Length;i++)
{
string ch = subData[i].Substring(0, 1);
if (ch == subField)
{
strDataContent = subData[i].Substring(1,subData[i].Length-1);
break;
}
}
}
return strDataContent;
}
//替换特殊字符
public string replaceChr(string result)
{
char[] arr;
int num;
arr = result.ToCharArray();
for (int i = 0; i < arr.Length; i++)
{
num = Convert.ToInt32(arr[i]);
if (num == 32)
{
arr[i] = '#';
}
else if (num == 30)
{
arr[i] = '@';
}
else if (num == 31)
{
arr[i] = '$';
}
else if (num == 29)
{
arr[i] = '%';
}
}
result = new string(arr);
return result;
}
//按目次地址长度除12分割
public string[] SplitMuCi(string strMuCi)
{
int len = strMuCi.Length / 12;
string[] splitedMuCi = new string[len];
for (int i = 0, j = 0; j < len; i += 12, j++)
{
splitedMuCi[j] = strMuCi.Substring(i, 12);
}
return splitedMuCi;
}
/// <summary>
/// 将目次地址区的分成3部份,返回分割后的结果
/// </summary>
/// <param name="strArr">调用SplitMuCi返回的结果</param>
/// <returns></returns>
public string[,] getData(string[] strArr)
{
int len = strArr.Length;
string[,] dataField = new string[len, 3];
for (int k = 0; k < len; k++)
{
int count = 0;
for (int i = 0, j = 3; count < 3; i += j, j++, count++)
{
dataField[k, count] = strArr[k].Substring(i, j);
}
}
return dataField;
}