给定一个ISBN文件,要求提取其中的‘-’,删除不规则的ISBN码,如何操作啊!
求大哥大姐!

解决方案 »

  1.   


    function IsISBN(ISBN: String): Boolean;
    var
    Number, CheckDigit: String;
    CheckValue, CheckSum, Err: Integer;
    i, Cnt: Word;
    begin
    {取得检验数字}
    CheckDigit := Copy(ISBN, Length(ISBN), 1);
    {Get rest of ISBN, minus check digit and its hyphen}
    Number := Copy(ISBN, 1, Length(ISBN) - 2);{ISBN长度必须为11,并且组成数字必须介于9和9或X}
    if (Length(Number) = 11) and (Pos(CheckDigit, '0123456789X') > 0) then
    begin
    {Get numeric value for check digit}
    if (CheckDigit = 'X') then
    CheckSum := 10
    else
    Val(CheckDigit, CheckSum, Err);
    {Iterate through ISBN remainder, applying decode algorithm}
    Cnt := 1;for i := 1 to 12 do begin
    {如果当前字符介于0~9,则不包含连字符}
    if (Pos(Number[i], '0123456789') > 0) then begin
    Val(Number[i], CheckValue, Err);
    {Algorithm for each character in ISBN remainder, Cnt is the nth
    character so processed}
    CheckSum := CheckSum + CheckValue * (11 - Cnt);
    Inc(Cnt);
    end;
    end;{校验最后的值能否被11整除}
    if (CheckSum MOD 11 = 0) then
    IsISBN := True
    else
    IsISBN := False;
    end
    else
    IsISBN := False;
    end;