procedure TForm12.btn1Click(Sender: TObject); var wokao: string; begin wokao := 'abcde_fg'; ShowMessage(IntToStr(wokao.IndexOf('_')));//5 ShowMessage(wokao.Substring(0,wokao.IndexOf('_')));//abcde end;