Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# make first letter uppercase

        System.Console.WriteLine(char.ToUpper(str[0]) + str.Substring(1));
Comment

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"
Comment

first sentence letter capital in c#

public static class StringExtension
{
    public static string CapitalizeFirst(this string s)
    {
        bool IsNewSentense = true;
        var result = new StringBuilder(s.Length);
        for (int i = 0; i < s.Length; i++)
        {
            if (IsNewSentense && char.IsLetter(s[i]))
            {
                result.Append (char.ToUpper (s[i]));
                IsNewSentense = false;
            }
            else
                result.Append (s[i]);

            if (s[i] == '!' || s[i] == '?' || s[i] == '.')
            {
                IsNewSentense = true;
            }
        }

        return result.ToString();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: overloading constructors c# 
Csharp :: how to detach the camera from the player after death unity 
Csharp :: Query Parent-GrandChild collection 
Csharp :: c# check if float value is positif 
Csharp :: unity update not called 
Csharp :: tomatch jest 
Csharp :: c# add field to expando object 
Csharp :: writeline in C# 
Csharp :: ActionExecutingContext result response return objects 
Csharp :: use string[] args c# 
Csharp :: Return out of a Ienumerator/Courotine in C# 
Csharp :: c# print expression tree 
Csharp :: how to create an initialized jtoken c# 
Csharp :: c# function<T 
Csharp :: unittest servicector automapper 
Csharp :: user control equivalent event for form.shown c# 
Csharp :: unity get object position on screen 
Csharp :: system.collections.generic.list 1 system.int32 c# 
Csharp :: particles are pink - creating tex and material 
Csharp :: "; expected" error c#$ 
Csharp :: button next for picturebox c# 
Csharp :: We create a PdfDocument, not a (MigraDoc) Document 
Csharp :: unity play audio from particle system 
Csharp :: c# half hour dropdown list 
Csharp :: two question marks together mean in C# 
Csharp :: telerik mvc grid round sum result 
Csharp :: c# wtssendmessage 
Csharp :: file.deletealltext 
Csharp :: remove language folders build visual studio 
Csharp :: using == is inefficient unity 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =