Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

first letter uppercase c#

// first letter of string
private string CapitalizeFirst (string input) {
  	char.ToUpper(myString[0]) + myString[1..]; // captalizes first letter
}

// first letter of each word
private string CapitalizeAll (string input) {
  	var words = input.Split(' '); // create array of words

  	// loop through all words and capitalize them
	for (int i = 0; i < words.length; i++) {
     	words[i] = CapitalizeFirst (words[i]);
    }
  
  	return string.Join(' ', words);
}

string myString = "hello world";

// results
CapitalizeFirst(myString); // "Hello world"
CapitalizeAll(myString); // "Hello World"
 
PREVIOUS NEXT
Tagged: #letter #uppercase
ADD COMMENT
Topic
Name
4+5 =