Solved

array storage

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

856 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