var Titlestr:string;
begin
     Titlestr:=ADOQuery1.Fieldbyname('DocTitle').AsString;
     if length(Titlestr)>50  then
     begin
          showmessage(Titlestr);
          Varlabel4.Caption:=copy(TitleStr,1,50);
          showmessage(copy(Titlestr,51,Length(Titlestr)-50));
          Sctvarlabel15.Caption:=copy(Titlestr,51,Length(Titlestr)-50);
     end else
     begin
          Varlabel4.Caption:=TitleStr;
          Sctvarlabel15.Caption:='';
     end;
为什么当我字符串中有',,'这种符号的时候show出来的str就是乱码.如果是’,,'好像和全角半角有关。

解决方案 »

  1.   

    /*================================================================
    //* 函 数 名:Func_DivisionString
    //* 参    数:Str_String:String;Str_Sign:String
    //*
    //* 功能描述: 把文字分割
    //*
    //* 返 回 值:文字列表
    //*
    //* 抛出异常:
    //*
    //* 作    者:
    //*================================================================
    Function  Func_DivisionString(Str_String:String;Str_Sign:String):TStringList;
    var
      SL_Result:TStringList;
      Str_sout:String;
      Int_i:Integer;
    begin
      SL_Result:=TStringList.Create;
      if length(Str_String)<>0 then
      begin
         Str_sout:='';
         for Int_i:=1 to length(Str_String) do
         begin
            if Str_String[Int_i]<>Str_Sign then
               Str_sout:=Str_sout+Str_String[Int_i]
            else
            begin
               if Str_sout<>'' then
               begin
                  SL_Result.Add(Trim(Str_sout));
                  Str_sout:='';
               end;
            end;
         end;
         result:=SL_Result;
      end
      else
      begin
         SL_Result.Clear;
         result:=SL_Result;
      end;
    end;
    //*================================================================
    //* 函 数 名:Func_CodeToName
    //* 参    数:SL_CodeFeild:TStringList;Str_CodeFelid:String;Str_NameFelid:String
    //*
    //* 功能描述: 由代码获取名称或由名称获取代码
    //*
    //* 返 回 值:文字
    //*
    //* 抛出异常:
    //*
    //* 作    者:
    //*================================================================
    Function  Func_CodeToName(SL_CodeFeild:TStringList;Str_CodeFelid,Str_NameFelid,Str_TableName:String;Str_Connect:String):TStringList;
    Var
      ADOQuy_GetName:TAdoQuery;
      Int_i:Integer;
      SL_Result:TStringList;
    Begin
      SL_Result:=TStringList.Create;
      ADOQuy_GetName:=TAdoquery.Create(Application);
      ADOQuy_GetName.ConnectionString:=Str_Connect;
      For Int_i:=0 to SL_CodeFeild.Count-1 do
      begin
         With ADOQuy_GetName Do
         begin
            Sql.Clear;
            SQL.Add('Select '+Str_NameFelid+' From '+Str_TableName+' Where '+Str_CodeFelid+'= '+
                                                                           QuotedStr(SL_CodeFeild.Strings[Int_i]));
            Open;
         end;
         SL_Result.Add(ADOQuy_GetName.FieldByName(Str_NameFelid).AsString);
      end;
      Result:=SL_Result;
      ADOQuy_GetName.Free;
    end;//*================================================================
    //* 函 数 名:Func_MTrimString
    //* 参    数:Str_String:String
    //*
    //* 功能描述: 去掉字符串中所有空格
    //*
    //* 返 回 值:文字
    //*
    //* 抛出异常:
    //*
    //* 作    者:
    //*================================================================
    Function  Func_MTrimString(Str_String:String):String;
    var
      Str_sout:String;
      Int_i,Int_k:Integer;
    begin
      if length(Str_String)<>0 then
      begin
         Int_k:=1;
         Str_sout:=Str_String;
         for Int_i:=1 to length(Str_String) do
         begin
            if Str_String[Int_i]<>' ' then
            begin
               Str_sout[Int_k]:=Str_String[Int_i];
               Int_k:=Int_k+1;
            end;
         end;
         result:=copy(Str_sout,1,Int_k-1);
      end
      else  result:='';
    end;
      

  2.   

    var Titlestr:widestring;
    不知道行不行, 試下!!