有一个符串"alsdjf-sdk"
我想取"-"左边的值用什么function?

解决方案 »

  1.   

    if Pos('_',s) > 0 then 
        Str := Copy(s,1,Pos('_',s) - 1 ) ;
      

  2.   

    s:='alsdjf-sdk'
    i:=Pos('_',s);
    if i>0 then 
      return:=Copy(s,1,Pos('_',s) - 1 ) 
    else
      return:='';
      

  3.   

    函数 function LeftStr(const AText: string; const ACount: Integer): string; 
    使用 StrUtils.pas
    功能 返回字符串AText左边的ACount个字符
    说明 LeftStr('123456', 3) = '123'
    参考 function System.Copy
    例子 Edit3.Text := LeftStr(Edit1.Text, SpinEdit1.Value);