Re: Trim a multiple line message to a single line
- From: Brian Cook <BrianCook@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 2 Aug 2007 13:00:03 -0700
Sent you an email with a sampling.
"Jesse Houwing" wrote:
Hello Brian,.
Could you send a sample file with two of these data blocks f what they should
look like and how you receive them directly to my email? I'll reply back
to this thread with a solution when I have time to go over it. My newsreader
keeps messing up your samples, so it would be easier if I had two text files.
Jesse
Jesse the data inside of the [] is static six digits for each line.
The total number of lines may vary anywhere from one to as much as 8
lines of data.
The line should look like this when pieced together;
2007/07/27 11:00:03 [153006]ARES_INDICATION 010.050.016.002 404.2.01
(6511)
RX 74 bytes 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48 52 00 52
02 02
C7 83 D7 07 07 1B 0B 00 00 00 00 28 0A 06 06 06 06 06 06 06 06 06 06
06 0A 06
06 06 0A 06 06 06 0A 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06
06 06 06 40
All in one big line without word wrap.
The next entry would be a different header (ARES_INDICATION for
example).
"Jesse Houwing" wrote:
Hello Brian,
2007/07/27 11:00:03 [153006]My guess is that these aren't the same length for every line. If they
were it would be easy:
regex = "^.{num}";
input = "...";
replacement = "";
result = Regex.Replace(regex, input, replacement,
RegexOptions.MultiLine);
If the part between [] is variable in length you'd have to choose a
more advanced way:
^[^\[]+\[[^\]]+\]
It's hard to read. But essentially it says:
^ start at the beginning of a line
[^\[]+ get everything that is not a [
\[ get the opening [
[^\]]+ get everything that is not a ]
\] get the closing ]
and replace that with an empty string.
should do the job.
Another option is to construct a strignbuilder, readline every line
of the original input, use substring of the first ] to chop of the
first part and add the resulting string to the stringbuilder.
The first solution (regex) is shorter and once you understand the
regex easy
to understand and maintain.
The second solution (stringbuilder) is a bit more complex in lines of
code,
easier to understand if you're not used to regex and probably a tad
faster.
Jesse
- Follow-Ups:
- Re: Trim a multiple line message to a single line
- From: Jesse Houwing
- Re: Trim a multiple line message to a single line
- References:
- Re: Trim a multiple line message to a single line
- From: Jesse Houwing
- Re: Trim a multiple line message to a single line
- From: Brian Cook
- Re: Trim a multiple line message to a single line
- From: Jesse Houwing
- Re: Trim a multiple line message to a single line
- Prev by Date: Re: Alternative to Thread.Sleep?
- Next by Date: Re: Padright
- Previous by thread: Re: Trim a multiple line message to a single line
- Next by thread: Re: Trim a multiple line message to a single line
- Index(es):
Relevant Pages
|