Forem

Frederik Van Lierde
Frederik Van Lierde

Posted on

1

String to CamelCase in dotNet

Camel case is the practice of writing phrases without spaces or punctuation. It indicates the separation of words with a single capitalized letter, and the first word starting with either case. Common examples include "iPhone" and "eBay".

Change to CamelCase

public static string ToCamelCase(this string text)
{
  TextInfo _textInfo = CultureInfo.InvariantCulture.TextInfo;
  char[] _camelCase = _textInfo.ToTitleCase(text).Replace(" ","").ToCharArray();

  _camelCase[0] = char.ToLower(_camelCase[0]);
  return new string(_camelCase);
}
Enter fullscreen mode Exit fullscreen mode

Explanation

To reach camelCase, we do the following

  1. First make it TitleCase
  2. Remove the " " (spaces)
  3. Lowercase the first character

NuGet Package

You can create the extension yourself, or you can download the latest version of CodeHelper.Core.Extensions

This packages contains much more cool and fun string extensions

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)