處理中英文的函式

露水上的青蛙發表於2013-08-07

function Fuzhi135(s: string): string;
var
  cCount,eCount,eCountNum,i,isum: Integer;
begin
  cCount := 0;
  eCount := 0;
  eCountNum := 0;
  for i := 1 to length(s) do
  begin
    if ByteType(s, i) = mbSingleByte then
      inc(cCount)
    else if ByteType(s, i) = mbLeadByte then
    begin
      Inc(eCount);
      eCountNum := eCountNum + 2;
    end;
    isum := cCount+ eCount;
    if isum=135 then
      Break;
  end;
  Result := Copy(s,1,cCount+eCountNum);
end;

function Fuzhi5(s: string): string;
var
  cCount,eCount,eCountNum,i,isum: Integer;
begin
  cCount := 0;
  eCount := 0;
  eCountNum := 0;
  for i := 1 to length(s) do
  begin
    if ByteType(s, i) = mbSingleByte then
      inc(cCount)
    else if ByteType(s, i) = mbLeadByte then
    begin
      Inc(eCount);
      eCountNum := eCountNum + 2;
    end;
    isum := cCount+ eCount;
    if isum=135 then
      Break;
  end;
  Result := Copy(s,cCount+eCountNum+1,10);
end;

function TotalStrSum(s: string): Integer;
var
  cCount,eCount,i: Integer;
begin
  cCount := 0;
  eCount := 0;
  for i := 1 to length(s) do
  begin
    if ByteType(s, i) = mbSingleByte then
      inc(cCount)
    else if ByteType(s, i) = mbLeadByte then
      inc(eCount);
  end;
  Result := eCount+cCount;
end;

相關文章