Re: Trim a multiple line message to a single line



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




.



Relevant Pages

  • Re: Trim a multiple line message to a single line
    ... 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? ... first part and add the resulting string to the stringbuilder. ... The first solution (regex) is shorter and once you understand the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Trim a multiple line message to a single line
    ... "Jesse Houwing" wrote: ... Find the location, split the string. ... private string LayoutInput ... Again you could use a regex for this... ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reading from file into an array
    ... Jesse Houwing ... string row = textIn.ReadLine; ... using (StreamReader textIn = new StreamReader(new FileStream(path, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: String format
    ... "Jesse Houwing" wrote: ... How is this possible?This string has many dates like above in the ... The MatchEvaluator is used to parse the dates (I used the exact ... format used here to make sure it parses correctly). ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trim a multiple line message to a single line
    ... public static string LayoutInput ... "Jesse Houwing" wrote: ... it's always the 34th Hex pair. ... Again you could use a regex for this... ...
    (microsoft.public.dotnet.languages.csharp)