D
D
Dmitry2018-04-17 09:38:34
ASP.NET
Dmitry, 2018-04-17 09:38:34

How to capitalize?

I have some kind of wild blunt. I can imagine how to do it, in my head there is an option how it will look approximately. I know that I need to use ToUpper and Substring. But I can not figure out how to push the condition into the model.
Actually here is a piece when, can someone tell me how to do it right?

var createEAD = new EAD
            {
                FileNumber = maxNumber,
                LastName = model.LastName,
                Name = model.Name,
                Patronymic = model.Patronymic,
                BirthDate = model.BirthDate,
                DateOfDismissal = model.DateOfDismissal,
                WandrobeNumberID = model.WandrobeNumber.ID,
                CellNumberID = model.CellNumber.ID,
                StatusEADID = model.StatusEAD.ID,
            };

How do I correctly capitalize LastName (for example)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2018-04-17
@Nardil

LastName = lastName[0].ToString().ToUpper() + lastName.Substring(1);

D
Dmitry, 2018-04-17
@Nardil

Basically based on the first answer, I ended up doing this:

LastName = model.LastName != null ?  model.LastName[0].ToString().ToUpper() + model.LastName.Substring(1) : model.LastName

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question