'Convert second character become ASCI number with multiplied 3
Dim MyInput As String, MyOutput As String
MyInput = TextBox4.Text.Trim()
MyOutput = Asc(Mid(MyInput, 2, 1)) * 3
TextBox5.Text = MyOutput
// In one line
int result = ((int)System.Text.ASCIIEncoding.ASCII.GetBytes(MyInput.Substring(1, 1))[0]) * 3;
// Broken down
string c = MyInput.Substring(1, 1); // Mid is the substring but in VB strings are 1 based and c#
// is 0 based which is why it is 1, 1 and not 2, 1
// Asc gets the ascii value of the character
byte[] asc = System.Text.ASCIIEncoding.ASCII.GetBytes(c);
// The above gets an array of bytes but as we only passed in a string of one length there should only
// be one byte in the array. Convert it to an int
int ascii = (int)asc[0];
// Multiply it by 3
ascii = ascii * 3;
Marked as answer by fialbz on Apr 28, 2012 11:08 PM
fialbz
Member
255 Points
161 Posts
Convert VB code into C# code
Apr 28, 2012 10:29 PM|LINK
I want to convert below VB code into C# code:
'Convert second character become ASCI number with multiplied 3 Dim MyInput As String, MyOutput As String MyInput = TextBox4.Text.Trim() MyOutput = Asc(Mid(MyInput, 2, 1)) * 3 TextBox5.Text = MyOutputPlease advise C# code for line-code: MyOutput = Asc(Mid(MyInput, 2, 1)) * 3
AidyF
Star
9246 Points
1576 Posts
Re: Convert VB code into C# code
Apr 28, 2012 10:41 PM|LINK
fialbz
Member
255 Points
161 Posts
Re: Convert VB code into C# code
Apr 28, 2012 11:17 PM|LINK
Yes, it's working.
For anyone, is there alternative C# code that more simply like my example VB code?