.NET equivalent of this java code

I'm interested if there is a function in .NET that can perform the same task that
"hu666.format("%c", venice3);" is performing. Thanks.

StringBuilder vart6 = new StringBuilder();
Formatter hu666 = new Formatter(vart6);

Object[] venice3 = new Object[]{Character.valueOf(paris4[15 & cleveland2 >> 4])};
hu666.format("%c", venice3);

Open in new window

Who is Participating?
Christopher KileConnect With a Mentor Commented:
The code can be converted if a fairly straightforward fashion except for the Character class, for which no exact member-for-member equivalent exists.  What operations do you need to perform on or using the Character class?  Whatever you need may be covered by a group of classes in .NET, but it would help to know due to the lack of a single equivalent class.

The >> 4 shift operator is the equivalent of an integer division by 16; the & operator has lower precedence than >> so the index expression is the equivalent of [15 & (cleveland2 / 16)].  Extended further, the 15 & is masking out all but the lowest four bits of the results of the shift, equivalent to (cleveland2 / 16) % 16.

While we don't have the Character class, examination of it tells us that .valueOf() accepts an intrinsic Java char,so we know what the array is filled with.  Assume the char type in Java contains Unicode (two-byte) and not ASCII (1-byte) characters.  Then this code captures the character in array.

Visual Basic
Dim c as Char = paris4(cleveland2 / 16) MOD 16)

Open in new window

Char c = paris4(cleveland2 / 16) % 16);  // the bit and shift operators will work the same in C# as in Java, but this works in VB as well

I hope this helps.  Please let me know what else you need from the Character class.  Thanks in advance.

Open in new window

Shahan AyyubSenior Software Engineer - iOSCommented:

I am not a Java guy but can help you out to find an equivalent in .net if you elaborate a little bit about your intentions in attached sample code.

My quick search on Java doc told me that `%c` in formatter class helps to find an equivalent unicode of the argument.

A part from Java doc:

'c', 'C'  character  The result is a Unicode character

So, you can use Encoding class. GetBytes and GetString functions can help you on that.

Check out the relevant example for how to use them:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.