Solved

array storage

Posted on 2007-03-26
2
190 Views
Last Modified: 2012-05-05
I have a string like "60165F010430313037"

I have to store each 2 chars in an byte array or simply an array like

a[0] = 60
a[1] = 16
a[2] = 5F

...like that
0
Comment
Question by:Rahamathulla_J
2 Comments
 
LVL 9

Expert Comment

by:WinterMuteUK
ID: 18792907
The simple route would be something like:

            string splitMe = "60165F010430313037";
            string[] a = new string[splitMe.Length / 2];
            int start = 0;
            for (int i = 0; i < splitMe.Length / 2; i++)
            {
                a[i] = splitMe.Substring(start, 2);
                start += 2;
            }

Not sure how you'd convert it to a byte array though.
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 250 total points
ID: 18793072
string source = "60165F010430313037";
byte[] bytes = new byte[source.Length/2];
for(int i=0 ; i < source.Length/2 ; i++)
{
  string s = source.Substring(2*i,2);
  b[i] = byte.Parse(s,System.Globalization.NumberStyles.HexNumber);
}
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now