"c# convert to snake case" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "c# convert to snake case" answered properly. Developers are finding an appropriate answer about c# convert to snake case related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like c# convert to snake case. Enter your desired code related query in the search bar and get every piece of information about C# code related question on c# convert to snake case.
c# convert to snake case
using System;
using System.Globalization;
using System.Text;
namespace Extensions
{
public static class StringExtensions
{
public static string ToSnakeCase(this string text)
{
if (string.IsNullOrEmpty(text))
{
return text;
}
var builder = new StringBuilder(text.Length + Math.Min(2, text.Length / 5));
var previousCategory = default(UnicodeCategory?);
for (var currentIndex = 0; currentIndex < text.Length; currentIndex++)
{
var currentChar = text[currentIndex];
if (currentChar == '_')
{
builder.Append('_');
previousCategory = null;
continue;
}
var currentCategory = char.GetUnicodeCategory(currentChar);
switch (currentCategory)
{
case UnicodeCategory.UppercaseLetter:
case UnicodeCategory.TitlecaseLetter:
if (previousCategory == UnicodeCategory.SpaceSeparator ||
previousCategory == UnicodeCategory.LowercaseLetter ||
previousCategory != UnicodeCategory.DecimalDigitNumber &&
previousCategory != null &&
currentIndex > 0 &&
currentIndex + 1 < text.Length &&
char.IsLower(text[currentIndex + 1]))
{
builder.Append('_');
}
currentChar = char.ToLower(currentChar, CultureInfo.InvariantCulture);
break;
case UnicodeCategory.LowercaseLetter:
case UnicodeCategory.DecimalDigitNumber:
if (previousCategory == UnicodeCategory.SpaceSeparator)
{
builder.Append('_');
}
break;
default:
if (previousCategory != null)
{
previousCategory = UnicodeCategory.SpaceSeparator;
}
continue;
}
builder.Append(currentChar);
previousCategory = currentCategory;
}
return builder.ToString();
}
}
}
Source: stackoverflow.com
All those coders who are working on the C# based application and are stuck on c# convert to snake case can get a collection of related answers to their query. Programmers need to enter their query on c# convert to snake case related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c# convert to snake case for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of c# convert to snake case while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "c# convert to snake case". Visit this developer's friendly online web community, CodeProZone, and get your queries like c# convert to snake case resolved professionally and stay updated to the latest C# updates.