I have rows of 8 numerical values in a text file that I have to parse. Each
value must occupy 10 spaces and can be either a decimal or an integer.
// these are valid - each fit in a 10 character block
123.8
123.8
1234.567
12345
12345
1234.567
// these are not valid
12 34.56 // whitespace in the middle of the value
1234 // occupies 11 spaces
// these are valid lines
// there is one value in each 10 character block
12345.678912345 .678912345.6789 12345.678912345 .678912345.6789 12345.678912345 .6789
345.6789 345.6789 45.6789 45.678912345.67 89 345.678912345.6 789
2345.6789
In reality the data can be in many different formats. (single values, rows
of 8 followed by an integer, rows of 10...) Currently I am parsing this with
code. For this example I read a line, break it up into an array of 8 values
of 10 characters each, and check to see if each one is numeric. If they are
all numeric, move on to the next line.
My biggest problem is how to deal with the whitespace. It can come before
the value, after the value, but not in the middle of the value. The value
can be of any length up to 10. It can be placed anywhere in the 10
character block and padded with whitespace. There are a lot of possible
variations. Also, I would like to generalize it to create the regular
expression on the fly for different formats.
Is there a way, using regular expressions, to specify a total width
including varing amounts of whitespace (depending on the size and position
of the value)?
Thanks for any help.
David 1 2689
David,
I don't think that you are going to get any real performance gains using
RegEx here. I also don't think that you are going to get a maintinence gain
either, since I can't think of a regex feature which will let you do this.
On top of that, you already have code that does this. It really doesn't
seem to difficult. Just read each line, read 10 characters, trim it, see if
it is a number, repeat.
Why fix it if it isn't broken?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"David" <dr*******@yaho o.com> wrote in message
news:uc******** ******@TK2MSFTN GP04.phx.gbl... I have rows of 8 numerical values in a text file that I have to parse. Each value must occupy 10 spaces and can be either a decimal or an integer.
// these are valid - each fit in a 10 character block 123.8 123.8 1234.567 12345 12345 1234.567
// these are not valid 12 34.56 // whitespace in the middle of the value 1234 // occupies 11 spaces
// these are valid lines // there is one value in each 10 character block 12345.678912345 .678912345.6789 12345.678912345 .678912345.6789 12345.678912345 .6789 345.6789 345.6789 45.6789 45.678912345.67 89 345.678912345.6 789 2345.6789
In reality the data can be in many different formats. (single values, rows of 8 followed by an integer, rows of 10...) Currently I am parsing this with code. For this example I read a line, break it up into an array of 8 values of 10 characters each, and check to see if each one is numeric. If they are all numeric, move on to the next line.
My biggest problem is how to deal with the whitespace. It can come before the value, after the value, but not in the middle of the value. The value can be of any length up to 10. It can be placed anywhere in the 10 character block and padded with whitespace. There are a lot of possible variations. Also, I would like to generalize it to create the regular expression on the fly for different formats.
Is there a way, using regular expressions, to specify a total width including varing amounts of whitespace (depending on the size and position of the value)?
Thanks for any help.
David
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
When users enter urls or other long strings it can destroy the
formatting of a page. A long url, posted in a comment, can cause page
distortions that make the page unreadable, till the website owner logs in
and deletes the comment. To protect against that, I'd like to break up
long strings in the comments (anything submitted by anonymous sources).
One thing I'd like to add to the following function is the ability to
break up long...
|
by: aevans1108 |
last post by:
expanding this message to microsoft.public.dotnet.xml
Greetings
Please direct me to the right group if this is an inappropriate place
to post this question. Thanks.
I want to format a numeric value according to an arbitrary regular
expression.
|
by: Ray Stevens |
last post by:
I would like to quickly strip out all non-numeric characters from a string
(including whitespace) into a new string (i.e., remove the edit mask). Would
RegEx be the best way to do this and, if so, what is the syntax?
|
by: Lubomir |
last post by:
Hi,
I am using the following pattern:
"\\b" + MySttring + "\\b"
If MyString is "one", this should pick up whole words like "one".
The problem is, it will pick up also the word: "one.two" How should I modify
the patter to pickup only "one"?
|
by: Just Me |
last post by:
I need a regex to do this.
Ignore < possibleWhiteSpace htmlTag
Replace whitespace anything >
With >
Basically I need to remove anything following the html tag up to and
| |
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: ommail |
last post by:
Hi
I wonder if regular expressions are in general sower than using
classes like String and
Char when used for validating/parsing text data?
I've done some simple test (using IsMatch()) method and the result was
that Regex
is either as fast or two times slower than method which used methods
from classes
|
by: CJ |
last post by:
Is this the format to parse a string and return the value between the item?
Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>");
I am trying to parse this string.
<File_Name>Services</File_Name>
Thanks
|
by: Jeff |
last post by:
I'm parsing this:
name="value"
and sometimes it looks like this:
name2="value2
without the closing '"'. I don't want to capture the end quote.
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |