how to capitalize every first letter with none before an apostrophe but with one after in javascript

Related searches

In javascript, I need to capitalize each first letter of words in a string (proper name) but not when before an apostrophe such as this example :

from henri d'oriona --> Henry d'Oriona

All I can get is something like Henry D'oriona or best case Henry D'Oriona.

Thanks for your help

Jacques

You could use the String.replace method with a regular expression to produce a one-liner solution.

Note that String.replace can accept a function for its second argument which can be used to loop through the matches and modify them as necessary.

const specialCapitalize = 
 str => str.replace(/(\w[^\'])+/gi, word => word[0].toUpperCase() + word.slice(1));

console.log(specialCapitalize("henri d'oriona some other words"))

Regular Expressions :: Eloquent JavaScript, In the following example, the u character is allowed to occur, but the pattern also the uppercase B in the input string, even though the pattern is itself all lowercase. The next element is the part matched by the first group (the one whose The part before the or operator matches two slash characters followed by any� Capitalize only the first letters in spreadsheet cells. Excel’s primary functions for editing the case of text are PROPER, UPPER and LOWER. However, none of those uppercase just the first letter in an Excel spreadsheet cell. Nevertheless, you can still add a formula to an Excel spreadsheet cell that capitalizes just the first letter of a text

First case but to great was: toTitleCase('henri d'oriona')

returns Henri D'orina function toTitleCase(str) {

    return str.replace(/\w\S*/g,
    function(txt) {
            return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
    }
    );

}

and best case scenario returning "Henri D'Oriona"

    function toProperCase(s) {
    return s.toLowerCase().replace( /\b((m)(a?c))?(\w)/g,
            function($1, $2, $3, $4, $5) { if($2){return $3.toUpperCase()+$4+$5.toUpperCase();}
    return $1.toUpperCase(); });

}

Capitalize the First Letter of a String in JavaScript, JavaScript has a String#uppercase() function that converts an entire string to uppercase. That means you can capitalize the first character and combine it with the substring containing everything but the first character. After installing Kutools for Excel, please do as follows:. 1.Select the data range that you want to use. 2.Click Kutools > Text > Change Case, see screenshot:. 3.In the Change Case dialog box, if you select Proper Case, the first letter of each word will be capitalized, see screenshot:

Create a function which will make the first letter upperCase called capitalize. After that, split the string by empty space and traverse the array obtained.

For each element from the resulted array apply capitalize :

let upperCase = capitalize(word);

Then join the values from array into one string.

const capitalize = (s) => {

  if (typeof s !== 'string') return ''
  let capitalWord = '';

  if (s.includes("d'")) {

    let nameAfterSpecialChar = s.split("d'")[1];
    let capitalName = nameAfterSpecialChar.charAt(0).toUpperCase() + nameAfterSpecialChar.slice(1)
    capitalWord = "d'" + capitalName

  } else {
    capitalWord = s.charAt(0).toUpperCase() + s.slice(1)
  }

  return capitalWord;
}

const makeNameWithCapital = (name) => { 
  var wordsList = name.split(" ");
  let arrOfNames = []

  for (let word of wordsList) {
    let upperCase = capitalize(word);
    arrOfNames.push(upperCase);
  }

  let nameWithUpper = arrOfNames.join(" ");
  console.log(nameWithUpper)
  
  return nameWithUpper;
}

const nameUnparsed= "henri d'oriona "
const nameUnparsed1 = "henri d'oriona d'example test"

makeNameWithCapital(nameUnparsed)
makeNameWithCapital(nameUnparsed1)

apostrophe-utils, Inherits from: apostrophe-module If you don't wish it was standard in JavaScript , it probably doesn't belong Calls to apos.utils.log , apos.utils.error , etc. are routed through this object by Apostrophe. Capitalize the first letter of a string. one space is required between them in matching documents, but� The ::first-letter CSS pseudo-element applies styles to the first letter of the first line of a block-level element, but only when not preceded by other content (such as images or inline tables). /* Selects the first letter of a <p> */ p::first-letter { font-size: 130%; } The first letter of an element is not always trivial to identify:

Capitalization, No one would argue with Coca-Cola or Pepsi Cola, but a case could be made for Royal Crown cola. If a trademark starts with a lowercase word or letter (e.g., eBay � how to capitalize every first letter with none before an apostrophe but with one after in javascript In javascript, I need to capitalize each first letter of words in a string (proper name) but not when before an apostrophe such as this example : from henri d'oriona --> Henry d'Oriona All I can

Capitalization After Colons, Reading the rules it indicated to capitalize the first letter after the colon. thus… fluency: A study.. Or the one I am not sure that can be used is this way. Poetry� If you do not want AutoCorrect to capitalize your words for you, use either of the following methods. Method 1: Turn off the "Capitalize first letter of sentences" feature. On the Tools menu, click AutoCorrect Options. Click the AutoCorrect tab. Click to clear the Capitalize first letter of sentences check box. Click OK. Method 2: Use the Undo

The first word in a quotation that is a complete sentence is capitalized, but the first word in a partial quotation is not: He said, “Life is just one damned thing after another.” He called journalism “literature in a hurry.” Word Order for Attribution

Comments
  • And what did you try till now?
  • This may help, but it doesn't take apostrophes into account. Shouldn't be too hard to adapt.
  • Neither of those produce the preferred results of "Henri d'Orina"