Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Convert first letter of string to lower case

I'm looking for a way to convert the first letter of a string to a lower case letter. The code I'm using pulls a random String from an array, displays the string in a text view, and then uses it to display an image. All of the strings in the array have their first letter capitalized but image files stored in the app cannot have capital letters, 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!

like image 811
cerealspiller Avatar asked Sep 23 '11 22:09

cerealspiller


People also ask

How do you lowercase the first letter of a string?

To capitalize the first letter of a string and lowercase the rest, use the charAt() method to access the character at index 0 and capitalize it using the toUpperCase() method. Then concatenate the result with using the slice() method to to lowercase the rest of the string.

How do I change capital letters to lowercase in Android?

Double-tap the shift key for caps lock Just double-tap the shift key and a blue indicator will light up. You'll know you're in all caps because the letter keys will change to uppercase. When you're ready to switch back to lowercase, just tap the shift key once again.

How do I force a string to lowercase?

The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.


1 Answers

    if (monb.length() <= 1) {
        monb = monb.toLowerCase();
    } else {
        monb = monb.substring(0, 1).toLowerCase() + monb.substring(1);
    }
like image 83
pents90 Avatar answered Sep 27 '22 20:09

pents90