Android: convert first letter of string to lowercase

I am looking for a way to convert the first letter of a string to a lowercase letter. The code I'm using pulls a random string from an array, displays the string in a text representation, and then uses it to display the image. All lines in the array have their first letter, but the image files stored in the application cannot be capitalized, of course.

String source = "drawable/" //monb is randomly selected from an array, not hardcoded as it is here String monb = "Picture"; //I need code here that will take monb and convert it from "Picture" to "picture" String uri = source + monb; int imageResource = getResources().getIdentifier(uri, null, getPackageName()); ImageView imageView = (ImageView) findViewById(R.id.monpic); Drawable image = getResources().getDrawable(imageResource); imageView.setImageDrawable(image); 

Thanks!

+7
source share
3 answers
  if (monb.length() <= 1) { monb = monb.toLowerCase(); } else { monb = monb.substring(0, 1).toLowerCase() + monb.substring(1); } 
+15
source
 public static String uncapitalize(String s) { if (s!=null && s.length() > 0) { return s.substring(0, 1).toLowerCase() + s.substring(1); } else return s; } 
+8
source

Google Guava is a Java library with many utilities and reusable components. To do this, the guava-10.0.jar library should be in the class path. The following example shows various CaseFormat transformations.

 import com.google.common.base.CaseFormat; public class CaseFormatTest { /** * @param args */ public static void main(String[] args) { String str = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, "studentName"); System.out.println(str); //STUDENT_NAME str = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "STUDENT_NAME"); System.out.println(str); //studentName str = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, "student-name"); System.out.println(str); //StudentName str = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "StudentName"); System.out.println(str); //student-name } } 

Output Like:

 STUDENT_NAME studentName StudentName student-name 
+2
source

All Articles