Solved

array storage

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 74
SQL Exceptions 3 43
Close form "before" open 3 39
application restarter  - for an exe that hangs 9 24
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 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

8 Experts available now in Live!

Get 1:1 Help Now