我对android中的子字符串感到困惑。在我的数据库中,我有像 DOGMATIKA-3.pdf 这样的文件 pdf,我想选择“pdf”。何在android中做到这一点?我只想选择最后3个字母,请任何人帮助我,谢谢。我已经尝试使用此代码,但强制关闭。
package mobile.download;
public class DownloadText extends Activity{
public Koneksi linkurl;
public Kondownload linkurl2;
String url;
String SERVER_URL;
String SERVER_URL2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.linkdownload);
TextView mTextLink = (TextView) findViewById(R.id.LinkDownload);
Bundle bundle = this.getIntent().getExtras();
String param1 = bundle.getString("keyIdc");
String param2 = bundle.getString("keyReference");
if(param2.substring(-3, 0).equals("pdf"))
{
linkurl = new Koneksi(this);
SERVER_URL = linkurl.getUrl();
SERVER_URL += "/moodledata/"+param1+"/"+param2;
mTextLink.setText(SERVER_URL);
Pattern pattern = Pattern.compile(SERVER_URL);
Linkify.addLinks(mTextLink, pattern, "");
}
else
{
linkurl2 = new Kondownload(param2);
SERVER_URL2 = linkurl2.getUrl();
mTextLink.setText(SERVER_URL2);
Pattern pattern = Pattern.compile(SERVER_URL2);
Linkify.addLinks(mTextLink, pattern, "");
}
}
}