.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

LVL 1
JPERKS1985Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shahan AyyubSenior Software EngineerCommented:
Hello!

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:

http://stackoverflow.com/questions/14560223/unicode-conversion-in-c-sharp
0
Christopher KileCommented:
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


C#
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.