-4

I have this string

string lol = "ISTO É APENAS O TESTE DA INFORMAÇÃO";

And the output has to be

string lol = "Isto é Apenas o Teste da Informação";

I made all the first letters of the words upper case but in some words I need to make them all lower case, like, if the word has only 3 letters it remains lower.

How can I do this ?

I already have this code :

 string unidade = "DIREÇÃO DE ANÁLISE E GESTÃO DA INFORMAÇÃO";

string lower=System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(unidade.ToLower());

And the output comes :

"Direção De Análise E Gestão Da Informação"

and I want to output to come as

"Direção de Análise e Gestão da Informação"

  • 2
    Have you tried anything? SO is not a code service but here to help you solve problems in what you have already tried – Gilad Green Jun 21 '17 at 10:57
  • 3
    Possible duplicate of [How to capitalize the first character of each word, or the first character of a whole string, with C#?](https://stackoverflow.com/questions/913090/how-to-capitalize-the-first-character-of-each-word-or-the-first-character-of-a) – valdeci Jun 21 '17 at 10:58

1 Answers1

0

To set to lower all the words below some length, you can split the words, and depending on its length set it to lower case. In this example i split on a space " ",if there's a possibility of another separators this would get more complicated:

string unidade = "DIREÇÃO DE ANÁLISE E GESTÃO DA INFORMAÇÃO";
string lower = System.Threading.Thread.CurrentThread.CurrentCulture
                               .TextInfo.ToTitleCase(unidade.ToLower());

lower = String.Join(" ", lower.Split(' ').Select(x => x.Length > 2 ? x : x.ToLower()));

In this case I'm setting to lower all words with less than 3 characters.

Pikoh
  • 7,582
  • 28
  • 53