Tnx 提前提供帮助。我想将我的点文件扩展名从大写转换为小写。例如:ABCD.JPG>>ABCD.jpg,xyz.PNG>>xyz.png
if ( attachemtnDescription.toString().endsWith(".JPG") || attachemtnDescription.toString().endsWith(".jpg")) {
attachmentPreviewImg.setImageResource(R.drawable.ic_support_attachment_image);
因为我有很多附件类型要声明,所以以大写和小写声明所有类型的附件都很忙,所以我想减少我的代码.
我有一种方法可以从上限/下限转换转换,但如何实现相同的方法......请帮忙。
EditText edit = (EditText)findViewById(R.id.email);
String input;
input = edit.getText().toString();
input = input.toLowerCase(); //converts the string to lowercase
or
input = input.toUpperCase();
我已经用过这个,希望它也能帮助你们。
if (attachmentName.toString().toLowerCase().endsWith(".jpg") || attachmentName.toString().toLowerCase().endsWith(".jpeg")) {
attachmentPreviewImg.setImageResource(R.drawable.ic_support_attachment_image);
使用 ".toLowerCase(( " 或 ">.toUpperCase((" 。
一个简单的
attachemtnDescription.toString().toUpperCase().endsWith(".JPG")
将解决您的问题,在进行比较之前将文件名转换为大写/小写。