将多行消息修剪为单行 [英] Trim a multiple line message to a single line

查看:68
本文介绍了将多行消息修剪为单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是数据的一个例子;


2007/07/27 11:00:03 [153006] ARES_INDICATION 010.050.016.002 404.2.01(6511)

RX 74 bytes

2007/07/27 11:00:03 [153006] 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13

48

2007/07/27 11:00:03 [153006] 52 00 52 02 02 C7 83 D7 07 07 1B 0B 00 00 00

00

2007/07/27 11:00:03 [153006] 28 0A 06 06 06 06 06 06 06 06 06 06 06 06 A 06

06

2007/07/27 11:00:03 [153006] 06 0A 06 06 06 0A 06 06 06 06 06 06 06 06 06

06

2007/07/27 11:00:03 [153006] 06 06 06 06 06 06 06 06 06 06

此项目的日期/时间和[]信息相同。


我想剥掉所有日期/时间和额外的[]信息并制作一条很大的

行。


任何帮助表示感谢。

This is an example of the data;

2007/07/27 11:00:03 [153006]ARES_INDICATION 010.050.016.002 404.2.01 (6511)
RX 74 bytes
2007/07/27 11:00:03 [153006] 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13
48
2007/07/27 11:00:03 [153006] 52 00 52 02 02 C7 83 D7 07 07 1B 0B 00 00 00
00
2007/07/27 11:00:03 [153006] 28 0A 06 06 06 06 06 06 06 06 06 06 06 0A 06
06
2007/07/27 11:00:03 [153006] 06 0A 06 06 06 0A 06 06 06 06 06 06 06 06 06
06
2007/07/27 11:00:03 [153006] 06 06 06 06 06 06 06 06 06 40
The Date/Time and [] information are the same for this one item.

I want to strip off all of the Date/Time and extra [] info and make one big
line.

Any help appreciated.

推荐答案

Hello Brian,
Hello Brian,

2007/07/27 11:00:03 [153 006]
2007/07/27 11:00:03 [153006]



我的猜测是,这些长度并不相同。如果它们是

就很容易:


regex =" ^。{num}" ;;

input = " ..." ;;

replacement ="" ;;

result = Regex.Replace(regex,input,replacement,RegexOptions.MultiLine);


如果[]之间的部分长度可变,你必须选择更多

的高级方式:


^ [^ \ [] + \ [[^ \]] + \]


很难读懂。但基本上它说:

^从一行的开头开始

[^ \ [] +得到的所有东西都不是[

\ [得到开场[

[^ \]] +得到一切不是]

\]得到结束]


并用空字符串替换它。


应该可以完成这项工作。


另一个选择是构建一个strignbuilder,readline

原始输入的每一行,使用第一部分的子字符串来切断第一部分和

将结果字符串添加到stringbuilder。


第一个解决方案(正则表达式)更短,一旦你理解正则表达式易于理解和维护。

第二个解决方案(stringbuilder) )在代码行中有点复杂,如果你不习惯正则表达式并且可能更快一点,那么更容易理解。


Jesse

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


Jesse []里面的数据是静态的每行x位数。


总行数可能从1到8行不等

数据。


拼凑时这条线看起来应该是这样的;


2007/07/27 11:00:03 [153006] ARES_INDICATION 010.050.016.002 404.2.01( 6511)

RX 74字节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 0A 06 06 06 0A 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06

06 40


所有在一条大线上没有自动换行。


下一个条目是不同的标题(例如ARES_INDICATION)。

" Jesse Houwing"写道:
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,
Hello Brian,

2007/07/27 11:00:03 [153006]
2007/07/27 11:00:03 [153006]



我的猜测是,每行的长度都不一样。如果它们是

就很容易:


regex =" ^。{num}" ;;

input = " ..." ;;

replacement ="" ;;

result = Regex.Replace(regex,input,replacement,RegexOptions.MultiLine);


如果[]之间的部分长度可变,你必须选择更多

的高级方式:


^ [^ \ [] + \ [[^ \]] + \]


很难读懂。但基本上它说:

^从一行的开头开始

[^ \ [] +得到的所有东西都不是[

\ [得到开场[

[^ \]] +得到一切不是]

\]得到结束]


并用空字符串替换它。


应该可以完成这项工作。


另一个选择是构建一个strignbuilder,readline

原始输入的每一行,使用第一部分的子字符串来切断第一部分和

将结果字符串添加到stringbuilder。


第一个解决方案(正则表达式)更短,一旦你理解正则表达式易于理解和维护。

第二个解决方案(stringbuilder) )在代码行中有点复杂,如果你不习惯正则表达式并且可能更快一点,那么更容易理解。


Jesse


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



Hello Brian,

你能发送一个带有两个数据块的样本文件,它们应该是什么样子,以及你如何将它们直接收到我的电子邮件?当我有时间检查时,我会用一个解决方案回复

给这个帖子。我的新闻阅读器

一直搞乱你的样本,所以如果我有两个文本文件会更容易。

Jesse

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 []内部的数据是每行的六位数。


总行数可以从1到8之间变化

数据行。


拼凑时这条线应该是这样的;


2007/07 / 27 11:00:03 [153006] ARES_INDICATION 010.050.016.002 404.2.01

(6511)

RX 74字节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 06 40


所有在一条大线上没有自动换行。


下一个条目将是一个不同的标题(ARES_INDICATION为

例子。


" Jesse Houwing"写道:
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,
>Hello Brian,

>> 2007/07/27 11: 00:03 [153006]
>>2007/07/27 11:00:03 [153006]


我的猜测是,每行的长度不一样。如果它们很容易:

regex =" ^。{num}";
input =" ..." ;;
replacement ="" ;;
result = Regex.Replace(正则表达式,输入,替换,
RegexOptions.MultiLine);
如果[]之间的部分长度可变必须选择更高级的方式:

^ [^ \ [] + \ [[^ \]] + \]

它很难读懂。但基本上它说:
^从一行的开头开始
[^ \ [] +得到的所有东西都不是[
\\ [[获得开放] [
[^ \]] +得到所有不是]
\]得到结束]
并用空字符串替换它。

应该做的工作。

另一种选择是构造一个strignbuilder,readline原始输入的每一行,使用第一个的子串]来切割
第一部分并将结果字符串添加到stringbuilder。

第一个解决方案(正则表达式)更短,一旦你理解了
正则表达式易于理解和维护。
第二个解决方案(stringbuilder)是代码行更复杂,如果你不习惯正则表达式,可能更容易理解
更快。
Jesse

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



这篇关于将多行消息修剪为单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆