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? 6 9444
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_C zar" <Co***********@ yahoo.com> wrote in message news:vo******** ****@corp.super news.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?
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.ToCharAr ray() 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_C zar" <Co***********@ yahoo.com> wrote in message
news:vo******** ****@corp.super news.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?
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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
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.jeppese n(#)durius.se> wrote in message
news:uW******** *****@TK2MSFTNG P10.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_C zar" <Co***********@ yahoo.com> wrote in message
news:vo******** ****@corp.super news.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?
"Computer_C zar" <Co***********@ yahoo.com> wrote in
news:vo******** ****@corp.super news.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
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_C zar" <Co***********@ yahoo.com> wrote in message
news:vo******** ****@corp.super news.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?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 $
Last-Modified: $Date: 2003/10/28 19:48:44 $
Author: A.M. Kuchling <amk@amk.ca>
Status: Draft
Type: Standards Track
|
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 might be a neat way to solve
this, but I am new to them. Can anyone give me a hint here?
The catch is, it must only find tokens that are not quoted and not
commented; examples follow
|
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 could give me a push...
Let's say I have the following XHTML file:
#v+
|
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.
What is the best way to do this? I was looking at sscanf, and
std::string find, but this seems kind of brute force to find the key,
get the pos, increment by 2 (for the = and first ") then grab everything
up to the next ". But maybe this is the...
|
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 ArrayList? I have tried
looping through the logfile using regex, if statements and flags to
find the start and end of each message but I do not see a good time in
this process to create a new instance of my Message object. While
messing around with...
| |
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:
“Unexpected end of file while parsing Name has occurred” isbeing
thrown.
Following is the part o xml I am trying to read:
<CHECK_ITEM_OUT>
|
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 RN(name, regex):
"""protect using () and give an optional name to a regex"""
if name:
|
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
"rag" ,"rock","yahoo"to my list.
I do not want to add any <subsignals"name value" to the list.i want
|
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 form pages, well over 500 potential fields, which are written in PHP. While most pages are one time entry forms, there are 5 that can be “recycled” as many times as needed. An example would be the Contacts Form. A user can give me 1 contact and move...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |