convert to c# byte

the conversion keep adding strings for this conversion.which is wrong.

  Function MakeByte(ByVal text As String) As Byte()

        Dim i As Integer
        Dim ba(text.Length - 1) As Byte
        For i = 1 To Len(text)
            ba(i - 1) = Asc(Mid(text, i, 1))
        Next

        Return ba

    End Function

Open in new window

LVL 9
Seven priceFull StackAsked:
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.

Ess KayEntrapenuerCommented:
Dont see a problem

view
0
Seven priceFull StackAuthor Commented:
I want it to convert to c# version. sorry
0
Ess KayEntrapenuerCommented:
you mean you want the same code in c#?

public byte[] MakeByte(string text)
{

	int i = 0;
	byte[] ba = new byte[text.Length];
	for (i = 1; i <= Strings.Len(text); i++) {
		ba[i - 1] = Strings.Asc(Strings.Mid(text, i, 1));
	}

	return ba;

}

Open in new window

0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Seven priceFull StackAuthor Commented:
you use converter and Strings.Le and Strings.Asc(Strings
do not exists in the current context.
0
Ess KayEntrapenuerCommented:
You could always add a reference to Microsoft.VisualBasic


or change to something like this


public byte[] MakeByte(string text)
{

	int i = 0;
	byte[] ba = new byte[text.Length];
	for (i = 1; i <= text.Length; i++) {
		ba[i - 1] = Microsoft.VisualBasic.Strings.Asc(text.Substring(i, 1));
	}

	return ba;

}

Open in new window





instead of Microsoft.VisualBasic.Strings.Asc(text.Substring(i, 1)); you can use (int)text.Substring(i, 1);



and it will give you the same zalue for a-z but for symbols, the values will be different (ie: # < > ...etc)

havent tried with capitals
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
Seven priceFull StackAuthor Commented:
tks
0
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
.NET Programming

From novice to tech pro — start learning today.