Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Capitalize The String

const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)

capitalize("follow for more")
// Result: Follow for more
Comment

Capitalize a String

const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)

capitalize("javascript one-liners are fun")
//Javascript one-liners are fun
Comment

function that capitalizes all words of a string

#include <stdio.h>
#define MAX 100

char *capitalize(char *s)
{
	char str[MAX]={0};	
	int i;
	
	//capitalize first character of words
	for(i=0; str[i]!=''; i++)
	{
		//check first character is lowercase alphabet
		if(i==0)
		{
			if((str[i]>='a' && str[i]<='z'))
				str[i]=str[i]-32; //subtract 32 to make it capital
			continue; //continue to the loop
		}
		if(str[i]==' ')//check space
		{
			//if space is found, check next character
			++i;
			//check next character is lowercase alphabet
			if(str[i]>='a' && str[i]<='z')
			{
				str[i]=str[i]-32; //subtract 32 to make it capital
				continue; //continue to the loop
			}
		}
		else
		{
			//all other uppercase characters should be in lowercase
			if(str[i]>='A' && str[i]<='Z')
				str[i]=str[i]+32; //subtract 32 to make it small/lowercase
		}
	}
	
	printf("Capitalize string is: %s
",str);
	
	return 0;
}
Comment

capitalize words in a string

/**
 * Capitalizes first letters of words in string.
 * @param {string} str String to be modified
 * @param {boolean=false} lower Whether all other letters should be lowercased
 * @return {string}
 * @usage
 *   capitalize('fix this string');     // -> 'Fix This String'
 *   capitalize('javaSCrIPT');          // -> 'JavaSCrIPT'
 *   capitalize('javaSCrIPT', true);    // -> 'Javascript'
 */
const capitalize = (str, lower = false) =>
  (lower ? str.toLowerCase() : str).replace(/(?:^|s|["'([{])+S/g, match => match.toUpperCase());
;
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get json data from json file in node js 
Javascript :: javascript check if object property exists 
Javascript :: javascript newline in alert box 
Javascript :: write bytes64 in json python 
Javascript :: mongoose check if string is objectid 
Javascript :: new jsonobject java 
Javascript :: dynamically add script code to page 
Javascript :: how to change text of div in javascript 
Javascript :: javascript replace text within dom 
Javascript :: how to loop through array of numbers in javascript 
Javascript :: javascript Multiline Arrow Functions 
Javascript :: fluttter http get 
Javascript :: chartjs disable animation 
Javascript :: auto closing parenthese not working on vscode 
Javascript :: check row empty array javascript 
Javascript :: how could you implement javascript into java 
Javascript :: dart list files in directory 
Javascript :: check device in flutter 
Javascript :: relaod the page in express 
Javascript :: delay statement in js 
Javascript :: statusbar reactnati 
Javascript :: reverse geocoding javascript map 
Javascript :: firebase cloud functions schedule function run time 
Javascript :: window.scroll 
Javascript :: For loop sum in javascript 
Javascript :: html add class 
Javascript :: using aria attributes in angular 
Javascript :: scroll event js 
Javascript :: set value array input jquery 
Javascript :: javascript get first 3 characters of string 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =