I have to capitalize first letter of text that i want to display. I searched for it but i cant found clear thing to do that, also there is no such props for text
in react native official documentation.
I am showing my text with following format:
<Text style={styles.title}>{item.item.title}</Text>
or
<Text style={styles.title}>{this.state.title}</Text>
How can I do it?
Suggestions are welcome?
create({ title: { fontSize: 18, textTransform: 'uppercase', }, }); If you want to capitalize the first letter of each word then you should use 'capitalize' value of textTransform style prop.
To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.
upper() method returns the uppercase string from the given string. It converts all lowercase characters to uppercase.
Write a function like this
Capitalize(str){ return str.charAt(0).toUpperCase() + str.slice(1); }
then call it from <Text>
tag By passing text as parameter
<Text>{this.Capitalize(this.state.title)} </Text>
You can also use the text-transform
css property in style:
<Text style={{textTransform: 'capitalize'}}>{this.state.title}</Text>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With