user372724
user372724

Reputation:

Equivalent of Format of VB in C#

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

Upvotes: 8

Views: 13539

Answers (6)

xagyg
xagyg

Reputation: 9721

Given this VB code:

Strings.Format(iCryptedByte, format)

Replace with this C# code:

var csformat = "{0:" + format + "}";
String.Format(csformat, iCryptedByte);

Upvotes: 1

Microsoft.VisualBasic.Strings.Format(iCryptedByte, "000");

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

Upvotes: 1

Peet Brits
Peet Brits

Reputation: 3265

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.

Upvotes: 2

Paul Michaels
Paul Michaels

Reputation: 16705

Try:

iCryptedByte.ToString("D3");

Upvotes: 0

Louis Rhys
Louis Rhys

Reputation: 35637

see String.Format

Upvotes: 0

abatishchev
abatishchev

Reputation: 100368

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

See MSDN 1, 2, 3

Upvotes: 11

Related Questions