Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# insert spaces before capital letters

string AddSpacesToSentence(string text, bool preserveAcronyms)
{
        if (string.IsNullOrWhiteSpace(text))
           return string.Empty;
        StringBuilder newText = new StringBuilder(text.Length * 2);
        newText.Append(text[0]);
        for (int i = 1; i < text.Length; i++)
        {
            if (char.IsUpper(text[i]))
                if ((text[i - 1] != ' ' && !char.IsUpper(text[i - 1])) ||
                    (preserveAcronyms && char.IsUpper(text[i - 1]) && 
                     i < text.Length - 1 && !char.IsUpper(text[i + 1])))
                    newText.Append(' ');
            newText.Append(text[i]);
        }
        return newText.ToString();
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# if statement 
Csharp :: sorting a list of objects in c# 
Csharp :: if file exist rename c# 
Csharp :: instantiate a player in photon 
Csharp :: unity check gameobject active 
Csharp :: get property value from object c# 
Csharp :: C# monogodb 
Csharp :: dictionary in c# unity 
Csharp :: datetime default c# 
Csharp :: asp.net model 
Csharp :: difference between boxing and unboxing in java 
Csharp :: c# unescape string 
Csharp :: c# increase length of array 
Csharp :: multi line comment c# 
Csharp :: c# find value in datagridview 
Csharp :: Long, Max and Min value 
Csharp :: c# remove item from list 
Csharp :: c# check if char is string 
Csharp :: checking a gamobjects layer 
Csharp :: c# swap name in string 
Csharp :: Edit file C# 
Csharp :: append 2 arrays c# 
Csharp :: default parameter c# 
Csharp :: if viewbag is null 
Csharp :: asp.net core identity get all roles 
Csharp :: yield c# 
Csharp :: asp.net format datetime 
Csharp :: pause unity game 
Csharp :: c# remove substring 
Csharp :: Allow edit in Datagrid C# 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =