This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So i've got a little testing table that i write little methods in before i implement them into my own codebase. I was making something that will swap a string from snake case to camel case and this was the best i could come up with.
static string OutName(string inName)
{
StringBuilder outName = new();
for (int i = 0; i < inName.Length; i )
{
if (i == 0)
{
outName.Append(Char.ToUpper(inName[i]));
}
else if (inName[i].Equals('_'))
{
if (i 1 != inName.Length)
{
outName.Append(Char.ToUpper(inName[i 1]));
}
i ;
}
else
{
outName.Append(inName[i]);
}
}
string endName = outName.ToString();
return endName;
}
I'm not super new to C# but whenever it comes to string manipulation i always want to default to C style arrays and memory allocation (its a hard habit to break lmao). Anyway, this feels pretty verbose for what i'm trying to do (and i could just be overthinking it) but it works great every time so i'm not mad, just wondering if anyone has done the same and came up with a different solution that might be a little more readable. If not, and you find this by googling, feel free to take it and use it. Happy Friday!
edit: oh lord its Saturday not Friday,
Subreddit
Post Details
- Posted
- 10 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/csharp/comm...