8

What will be the equivalent code for Format(iCryptedByte, "000") (VB.NET) in C# ?

Kiquenet
  • 13,820
  • 33
  • 141
  • 236

6 Answers6

11
String.Format(format, iCryptedByte); // where format like {0:D2}

See MSDN 1, 2, 3

abatishchev
  • 95,331
  • 80
  • 293
  • 426
2

Another very useful site for C# string formatting: http://blog.stevex.net/string-formatting-in-csharp/

Instead of {0:D3} you can also use the zero placeholder, e.g. {0:000} will pad with zeros to minimum length of three.

Peet Brits
  • 2,325
  • 24
  • 46
1
Microsoft.VisualBasic.Strings.Format(iCryptedByte, "000");

You'll need to add a reference to the Microsoft.VisualBasic assembly.

1

Given this VB code:

Strings.Format(iCryptedByte, format)

Replace with this C# code:

var csformat = "{0:" + format + "}";
String.Format(csformat, iCryptedByte);
xagyg
  • 9,304
  • 2
  • 29
  • 28
0

see String.Format

Louis Rhys
  • 32,677
  • 53
  • 143
  • 218
0

Try:

iCryptedByte.ToString("D3");
Paul Michaels
  • 15,217
  • 40
  • 143
  • 262