改写delphi一个方法(C#)在线等.......

来源:百度知道 编辑:UC知道 时间:2024/06/17 12:50:08
function GetMarcData(strMarc: string; ControlCord: string): string;
var
intPos, i, intStart, intLen, intAddr: Integer;
strMarcData, strHead, strLen, strStart, strFd, str1, strAddr, strDataLen,
strCode, strData, strMarcRec: string;
begin
intPos := Pos(cMarcRecordSign, strMarc);
strHead := Copy(strMarc, 1, intPos - 1);
for i := 1 to 24 - Length(strHead) do strHead := strHead + ' ';
strFd := Copy(strMarc, intPos + 2, Length(strMarc) - intPos);
intPos := Pos(cMarcRecordSign, strFd);
intStart := 0;
strMarc := '';
strMarcData := '';
while intPos>0 do
begin
if intPos>0 then
begin
str1 := Copy(strFd, 1, intPos - 1);
strCode := Copy(str1, 1, 3);
strData := Copy(str1, 4, Length(str1) - 3);
if strCode='001' then strData := ControlCord;
if strCode='005' then strData := FormatDateTi

改写中主要有三点问题:
1、源代码未定义变量cMarcRecordSign,补充在了函数参数中,也可能是预定义的公共变量,请根据情况自行修改;
2、Delphi中的Copy函数中字符的起始位置为从1开始,而C#中的Substring函数中字符的起始位置为从0开始,类似数组的存贮位置,所以在改写时,要注意对位置进行转换;
3、没有具体数据环境,无法进行实际测试,请自行进行测试,如果存在问题,应该主要是要点2中说明的字符串位置问题。
改写C#方法如下

static string GetMarcData(string strMarc, string ControlCord, string cMarcRecordSign)
{
int intPos, i, intStart, intLen, intAddr;
string strMarcData, strHead, strLen, strStart, strFd, str1, strAddr, strDataLen, strCode, strData, strMarcRec;
intPos = cMarcRecordSign.IndexOf(strMarc) + 1;
strHead = strMarc.Substring(0,intPos - 1);
for (i = 1; i<=(24-strHead.Length ); i++)
strHead += " ";

strFd = strMarc.Substring(intPos + 2 - 1, strMarc.Length - intPos);
intPos = cMarcRecordSign.IndexOf(strFd);
intStart = 0;
strMarc = "";
strMarcData = "";
while (intPos>=0)