473,513 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing string for hex values ...

I'm trying to figure out the best way to parse an input string from a file
for hex values. The string is actually Motorola S code produced by an
embedded assembler. For example lines contain S1142CD0XXYYZZ... I've
written similar programs in C/C++ where I save the string and use a pointer
to index along the string.

Well I've heard pointers are "evil" within C# but possible. Given that what
would be the desired method? Some of the values are 16 bit and some are 8
bit so I need to be flexible. Plus I'd also like to convert the hex values
to decimal for some math.

Can someone give me a recommendation or a "pointer" to how to approach it?
Nov 15 '05 #1
6 9434
Hi,

You can use pointers if you need performance. This requires that your app runs in FullTrust though.
You could also just keep your own "pointer" in an int:

string s = "abcdef";
int i = 0;
char c = s[i];

I would only resort to using pointers if you're doing *lots* of parsing.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Computer_Czar" <Co***********@yahoo.com> wrote in message news:vo************@corp.supernews.com...
I'm trying to figure out the best way to parse an input string from a file
for hex values. The string is actually Motorola S code produced by an
embedded assembler. For example lines contain S1142CD0XXYYZZ... I've
written similar programs in C/C++ where I save the string and use a pointer
to index along the string.

Well I've heard pointers are "evil" within C# but possible. Given that what
would be the desired method? Some of the values are 16 bit and some are 8
bit so I need to be flexible. Plus I'd also like to convert the hex values
to decimal for some math.

Can someone give me a recommendation or a "pointer" to how to approach it?

Nov 15 '05 #2
Computer_Czar, here are a couple of suggestions which might help you out.

1. Could you just use Substring to extract the strings and then Parse() to
parse the strings as hex values?
2. Could you use string.ToCharArray() to get a char array and then walk
through that array? That's probably going to yield code the most similar to
your C++ pointer code.
3. If you really have to you can use pointers in an unsafe block. I
wouldn't recommend it for this though since it seems there are some good
managed options.

--
Greg Ewing [MVP]
http://www.claritycon.com/

"Computer_Czar" <Co***********@yahoo.com> wrote in message
news:vo************@corp.supernews.com...
I'm trying to figure out the best way to parse an input string from a file
for hex values. The string is actually Motorola S code produced by an
embedded assembler. For example lines contain S1142CD0XXYYZZ... I've
written similar programs in C/C++ where I save the string and use a pointer to index along the string.

Well I've heard pointers are "evil" within C# but possible. Given that what would be the desired method? Some of the values are 16 bit and some are 8
bit so I need to be flexible. Plus I'd also like to convert the hex values to decimal for some math.

Can someone give me a recommendation or a "pointer" to how to approach it?

Nov 15 '05 #3
Computer_Czar <Co***********@yahoo.com> wrote:
I'm trying to figure out the best way to parse an input string from a file
for hex values. The string is actually Motorola S code produced by an
embedded assembler. For example lines contain S1142CD0XXYYZZ... I've
written similar programs in C/C++ where I save the string and use a pointer
to index along the string.

Well I've heard pointers are "evil" within C# but possible. Given that what
would be the desired method? Some of the values are 16 bit and some are 8
bit so I need to be flexible. Plus I'd also like to convert the hex values
to decimal for some math.

Can someone give me a recommendation or a "pointer" to how to approach it?


I can't see why you'd really need pointers here - just store how far
along the string you've gone with an integer.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Thanks for the reply ... you and everyone gave great suggestions. I'll take
a cut at it. I guess my main difficulty is or was understanding what
facilities existed within C# to perform the various tasks.
"Robert Jeppesen" <robert.jeppesen(#)durius.se> wrote in message
news:uW*************@TK2MSFTNGP10.phx.gbl...
Hi,

You can use pointers if you need performance. This requires that your app runs in FullTrust though. You could also just keep your own "pointer" in an int:

string s = "abcdef";
int i = 0;
char c = s[i];

I would only resort to using pointers if you're doing *lots* of parsing.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Computer_Czar" <Co***********@yahoo.com> wrote in message

news:vo************@corp.supernews.com...
I'm trying to figure out the best way to parse an input string from a file for hex values. The string is actually Motorola S code produced by an
embedded assembler. For example lines contain S1142CD0XXYYZZ... I've
written similar programs in C/C++ where I save the string and use a pointer to index along the string.

Well I've heard pointers are "evil" within C# but possible. Given that what would be the desired method? Some of the values are 16 bit and some are 8 bit so I need to be flexible. Plus I'd also like to convert the hex values to decimal for some math.

Can someone give me a recommendation or a "pointer" to how to approach it?


Nov 15 '05 #5
"Computer_Czar" <Co***********@yahoo.com> wrote in
news:vo************@corp.supernews.com:
I'm trying to figure out the best way to parse an input string from a
file for hex values. The string is actually Motorola S code produced
by an embedded assembler. For example lines contain S1142CD0XXYYZZ...
I've written similar programs in C/C++ where I save the string and
use a pointer to index along the string.


A good way might be to use the Regex class with a search pattern of

[0-9A-Fa-f]+

and then process the results. This will pick out strings of characters
which represent valid hex numbers. If you only want a certain number of
characters (to guarantee that you can int.Parse or long.Parse) then use
quatifiers - for example:

[0-9A-Fa-f]{1,8} -- matches 1..8 hex characters
-mbray
Nov 15 '05 #6
Pointers are for something else. They really don't apply here unless you
are a masochist to yourself and a sadist to those who will maintain your
code in the future. :-)

If I guess your intent correctly, you would want to use SubStr to pull out a
hex value in a known position and use Convert.ToInt32 to turn it into a
number.

"Computer_Czar" <Co***********@yahoo.com> wrote in message
news:vo************@corp.supernews.com...
I'm trying to figure out the best way to parse an input string from a file
for hex values. The string is actually Motorola S code produced by an
embedded assembler. For example lines contain S1142CD0XXYYZZ... I've
written similar programs in C/C++ where I save the string and use a pointer to index along the string.

Well I've heard pointers are "evil" within C# but possible. Given that what would be the desired method? Some of the values are 16 bit and some are 8
bit so I need to be flexible. Plus I'd also like to convert the hex values to decimal for some math.

Can someone give me a recommendation or a "pointer" to how to approach it?

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9425
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
17
2764
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
12
2518
by: Klaus Alexander Seistrup | last post by:
Hi group, I am new to xgawk (and seemingly to xml also), and I've been struggling all afternoon to have xgawką parsing an XHTML file containing a hCard˛, without luck. I wonder if you guys...
3
1384
by: Bryan | last post by:
If I have the following string from a huge xml file: std::string s = "<input key1=\"v1\" key2=\"val4\" key3=\"test\" />"; I need to get the values associated with the keys out from this line....
9
1971
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
3
3293
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception:...
3
2691
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
3
1656
by: raghudr | last post by:
Hi all, I am parsing a .xml file.My main intention is to retrieve the name value of node "Signal":- "Name Value" which is "rag". i want to store only the <signal"name value" that is only...
1
2187
nine72
by: nine72 | last post by:
Ok, I am at a complete loss on this and have finally come to the XML Parsing Gods (and perhaps a PHP minor deity) for guidance… I will try my best to describe what I have going on… 1) I have 15...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.