2017-06-16 32 views
1

Tnx提前帮助。我想将我的点文件扩展名从大写字母转换为小写字母。例如:ABCD.JPG >> ABCD.jpg,xyz.PNG >> xyz.pngAndroid:将.extensions转换为下/大写

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(); 
+0

这可能会帮助您重命名。 stackoverflow.com/a/2896829/1977021 – invisbo

回答

1

一个简单attachemtnDescription.toString().toUpperCase().endsWith(".JPG")将解决你的问题,将文件名转换为大写/小写做比较之前。

3

我用过这个,希望它也能帮助你们。

if (attachmentName.toString().toLowerCase().endsWith(".jpg") || attachmentName.toString().toLowerCase().endsWith(".jpeg")) { 
             attachmentPreviewImg.setImageResource(R.drawable.ic_support_attachment_image); 

使用 “.toLowerCase()” 或 “.toUpperCase()”。