I’m trying to format a string in c# and i m not sure if i shoudl be using regex or something like that basically if a modelname is md234GH and Dgh321Hh They need to be MD234gh and DGH321hh.
So capitals numbers lowercase
I tried doing the following:
TextInfo textInfo = new CultureInfo("en-GB", false).TextInfo;
foreach (var product in products)
{
if (product.ModelName != null)
{
product.ModelName = product.ModelName.ToLower();
product.ModelName = textInfo.ToTitleCase(product.ModelName);
}
}
but this only makes the first letter capital.
Any advice appreciated
ToTitleCaseis only mean to make the first letter of each word upper case. To do what you want, you’ll need to split the string up and call.ToUpperand.ToLoweras appropriate, e.g.: