in Education by
I am looking for a solution that capitalizes each word of the input string to cell seperated by blank space or dot (similar to proper function). I know it is broken but what I tried so far: /*Capitalize Firt Letter of Each Word of input String in Cell*/ if(activeRow > 1 && activeCol == 3 && ss.getSheetName() == validSheet && activeCell.isBlank() == false) { var inputVal = activeCell.getValue().toString(); Logger.log(inputVal); activeCell.setFormulaR1C1("=PROPER("+inputVal+")"); } Example: Input for cell A2: this tExt neEds to be fixed Output (Desired Result) for cell A2: This Text Needs To Be Fixed Thanks in advance Edit 1: I noticed that proper function won't work because it requires cell value in it. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Here's a function that takes a string and capitalizes the first letter of each word: function capitalizePhrase(phrase) { var reg = /\b(\w)/g; function replace(firstLetters) { return firstLetters.toUpperCase(); } capitalized = phrase.replace(reg, replace); return capitalized; } which you could then use like this: var inputVal = activeCell.getValue().toString(); var outputVal = capitalizePhrase(inputVal); activeCell.setValue(outputVal); Edit - if you also want to set other letters in the word to lower case, you can use this function instead: function properCase(phrase) { var regFirstLetter = /\b(\w)/g; var regOtherLetters = /\B(\w)/g; function capitalize(firstLetters) { return firstLetters.toUpperCase(); } function lowercase(otherLetters) { return otherLetters.toLowerCase(); } var capitalized = phrase.replace(regFirstLetter, capitalize); var proper = capitalized.replace(regOtherLetters, lowercase); return proper; }

Related questions

0 votes
    java program to input any string then print each word along with their length Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    I am trying to figure out how to pull only specific rows and columns using Google apps script. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    Each card bears one letter from the word mathematics'. The cards are placed on a table upside down. Find the ... the letter m'. Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
0 votes
    How will you capitalizes first letter of string?...
asked Nov 25, 2020 in Technology by JackTerrance
0 votes
    Which is not an option of Types of Case in LIbre office a) Upper b) Capitalize Each word c) Lower d) ... I will mark the brainlist Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
0 votes
    by default new document in word are letter sized paper true or false Select the correct answer from above options...
asked Dec 6, 2021 in Education by JackTerrance
0 votes
    by default new document in word are letter sized paper true or false Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    by default new document in word are letter sized paper true or false Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    A single letter is selected at random from the word ‘PROBABILITY’. The probability that it is a vowel is A. 1/3 B. 4/11 C. 2/11 D. 3/11 Select the correct answer from above options...
asked Nov 20, 2021 in Education by JackTerrance
0 votes
    If a single letter is selected at random from the word "PROBABILITY", then the probability that it is a vowel is A. 1 ... 2 11 D. 3 11 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    BCDEFGHIJKLMNOPQRSTUVWXYZ Riddle What word or Phrase or letter is it representing abcdefghijklmnopqrstvwxyz...
asked Feb 10, 2021 in Education by JackTerrance
0 votes
    c. To copy a formula in Microsoft Excel, you select the cell and drag this symbol that appears on the lower ... 7 computer please help Select the correct answer from above options...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    To copy a formula in Microsoft Excel, you select the cell and drag this ___ write one word Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    To copy a formula in Microsoft Excel, you select the cell and drag this ___ write one word Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
...