0

I have a string of full capitalized. I only want the first letter of a word in uppercase other in lower case. for eg: ALREADY BILLED TO COMPANY PLAN. I want it as 'Already Billed To Company Plan'. How to convert it in Reactjs? But actually the string is in an array which more string. I want to convert each string in that array.

Lex V
  • 1,414
  • 4
  • 17
  • 35
  • it may help you https://stackoverflow.com/questions/5956942/is-there-a-js-equivalent-to-css-text-transform-capitalize – Ashad Nasim Oct 21 '19 at 05:58

3 Answers3

3

You can use css for it using this

.your-class {
   text-transform: capitalize;
}

or if you want pure ReactJS styling you can use this

<div style={{ textTransform: 'capitalize' }}> Your text </div>

Working sample

.capitalize {
  text-transform: capitalize;
}
<div class="capitalize"> this text should be capitalized using css </div>
JkAlombro
  • 1,696
  • 1
  • 16
  • 30
0

Well aside from splitting the string by spaces and then finding the first character of each substring and using .toUpperCase to ensure it is uppercase and then converting the rest of the string using .toLowerCase, you could consider putting the text in a class and apply text-transform: uppercase; to the CSS class.

Alister
  • 453
  • 6
  • 15
0

You can do this in CSS, just wrap your element in span and add a class of text-transform: capatilize

for eg

<span className='capatilize'>
{
your content
}
</span>

But if you want to use in js only then this question and its answer may help you

Basically use create one function and in that function, with the help of regular expression, you can convert into capitalizing.

Ashad Nasim
  • 2,511
  • 21
  • 37