Remove "/" from a DateTime.ToShortDateString ();

6

I'm implementing a program using C # with .NET 3.5

I have the following code:

StringBuilder sb = new StringBuilder();
sb.Append(caminhoSalvarCobranca);
sb.Append(@"\Boleto ");
sb.Append(boleto.Sacado.Nome);
sb.Append(boleto.Boleto.DataVencimento.ToShortDateString);

" boleto.Boleto.DataVencimento.ToShortDateString " returns a string in the date format "dd / mm / yyyy". Would you have some function to remove the slashes ("/") and leave only the date (ddmmaaaa)?

    
asked by cumpadi 28.05.2014 в 18:31
source

2 answers

6

You can do this as follows:

sb.Append(boleto.Boleto.DataVencimento.ToString("ddMMaaaa");

In this way, ToString("...") formats the date in the desired format and avoids manipulating strings already created.

Note: For more formatting options for DateTime see this page .

    
answered by 28.05.2014 / 18:36
source
3

You may be doing too:

sb.Append(boleto.Boleto.DataVencimento.ToShortDateString().Replace("/","")); // ddMMyyyy
    
answered by 28.05.2014 в 18:45