Solved

array storage

Posted on 2007-03-26
2
195 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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