2017-06-16 33 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()」。