hd(re:split(Host, ":", [{return, list}]))
re:split 功能还是非常强大的
split(Subject, RE, Options) -> SplitList
Types:
| global
| notbol
| noteol
| notempty
| {offset, integer() >= 0}
| {newline, nl_spec()}
| bsr_anycrlf
| bsr_unicode
| {return, ReturnType}
| {parts, NumParts}
| group
| trim
| CompileOpt
This function splits the input into parts by finding tokens according to the regular expression supplied.
The splitting is done basically by running a global regexp match and dividing the initial string wherever a match occurs. The matching part of the string is removed from the output.
As in the re:run/3 function, an mp() compiled with the unicode option requires the Subject to be a Unicode charlist(). If compilation is done implicitly and the unicode compilation option is given to this function, both the regular expression and the Subject should be given as valid Unicode charlist()s.
The result is given as a list of "strings", the preferred datatype given in the return option (default iodata).
If subexpressions are given in the regular expression, the matching subexpressions are returned in the resulting list as well. An example:
re:split("Erlang","[ln]",[{return,list}]).
will yield the result:
["Er","a","g"]
while
re:split("Erlang","([ln])",[{return,list}]).
will yield
["Er","l","a","n","g"]
The text matching the subexpression (marked by the parentheses in the regexp) is inserted in the result list where it was found. In effect this means that concatenating the result of a split where the whole regexp is a single subexpression (as in the example above) will always result in the original string.
As there is no matching subexpression for the last part in the example (the "g"), there is nothing inserted after that. To make the group of strings and the parts matching the subexpressions more obvious, one might use the group option, which groups together the part of the subject string with the parts matching the subexpressions when the string was split:
re:split("Erlang","([ln])",[{return,list},group]).
gives:
[["Er","l"],["a","n"],["g"]]
Here the regular expression matched first the "l", causing "Er" to be the first part in the result. When the regular expression matched, the (only) subexpression was bound to the "l", so the "l" is inserted in the group together with "Er". The next match is of the "n", making "a" the next part to be returned. Since the subexpression is bound to the substring "n" in this case, the "n" is inserted into this group. The last group consists of the rest of the string, as no more matches are found.
By default, all parts of the string, including the empty strings, are returned from the function. For example:
re:split("Erlang","[lg]",[{return,list}]).
will return:
["Er","an",[]]
since the matching of the "g" in the end of the string leaves an empty rest which is also returned. This behaviour differs from the default behaviour of the split function in Perl, where empty strings at the end are by default removed. To get the "trimming" default behavior of Perl, specify trim as an option:
re:split("Erlang","[lg]",[{return,list},trim]).
The result will be:
["Er","an"]
The "trim" option in effect says; "give me as many parts as possible except the empty ones", which might be useful in some circumstances. You can also specify how many parts you want, by specifying {parts,N}:
re:split("Erlang","[lg]",[{return,list},{parts,2}]).
This will give:
["Er","ang"]
Note that the last part is "ang", not "an", as we only specified splitting into two parts, and the splitting stops when enough parts are given, which is why the result differs from that of trim.
More than three parts are not possible with this indata, so
re:split("Erlang","[lg]",[{return,list},{parts,4}]).
will give the same result as the default, which is to be viewed as "an infinite number of parts".
Specifying 0 as the number of parts gives the same effect as the option trim. If subexpressions are captured, empty subexpression matches at the end are also stripped from the result if trim or {parts,0} is specified.
If you are familiar with Perl, the trim behaviour corresponds exactly to the Perl default, the {parts,N} where N is a positive integer corresponds exactly to the Perl behaviour with a positive numerical third parameter and the default behaviour of re:split/3 corresponds to that when the Perl routine is given a negative integer as the third parameter.
Summary of options not previously described for the re:run/3 function:
Specifies how the parts of the original string are presented in the result list. The possible types are:
Groups together the part of the string with the parts of the string matching the subexpressions of the regexp.
The return value from the function will in this case be a list() of list()s. Each sublist begins with the string picked out of the subject string, followed by the parts matching each of the subexpressions in order of occurrence in the regular expression.
Specifies the number of parts the subject string is to be split into.
The number of parts should be a positive integer for a specific maximum on the number of parts and infinity for the maximum number of parts possible (the default). Specifying {parts,0} gives as many parts as possible disregarding empty parts at the end, the same as specifying trim
Specifies that empty parts at the end of the result list are to be disregarded. The same as specifying {parts,0}. This corresponds to the default behaviour of the split built in function in Perl.
相关推荐
asp.net 导入excel时,处理合并表头、复杂表头、多行表头 1.解决复杂表头的Excel导入。可以解决任何复杂的表头。 2.导入时,显示请稍后。。。提醒框,完毕后会自动隐藏 3.全面扫描Excel数据,将所有异常详细信息写入...
标题"qt 表格多行表头,复杂表头"正是指向这样一个需求。在描述中提到的“占用两行数据,利用合并表格功能实现多行表头”是实现这一功能的一种方法。下面将详细介绍如何在Qt中使用QTableWidget来创建这样的多行表头...
在Excel中,多层表头是一种常见的数据组织方式,它能帮助用户更清晰地呈现复杂的数据结构,尤其在处理分类和子分类数据时显得尤为重要。本文将深入探讨如何在Excel中实现多层表头的导出,以及如何进行单元格合并,以...
GridView 多表头实现与表头合并、分组 GridView 是一个常用的数据网格控件,但是在实际开发中,我们经常会遇到需要实现多表头、表头合并、表头分组等需求。今天,我们将探讨如何实现 GridView 多表头、表头合并、...
本示例将探讨如何利用DevExpress实现多行表头,也就是所谓的“复合表头”。复合表头在统计报表中非常常见,它可以清晰地展示多层次的分类数据,使用户更容易理解和分析数据。 首先,我们要了解DevExpress中的...
当我们需要展示的数据具有层次结构,比如分类或分组信息时,多层表头(二维表头)就显得尤为重要。本篇文章将深入探讨如何在C#中实现`DataGridView`的二维表头功能,以及如何进行表头的合并单元格操作。 首先,我们...
//表头1 要合并的格表头描述字段 已@分割 注意 这里的表头是至第一行表头 var gauge_head2="日期@交易量汇总@设备占比@WEB占比@APP占比@互生币支付@互商订单支付@代兑互生币@兑换互生币@货币转银行";// 表头描述...
总之,利用 Apache POI 实现多表头的 Excel 导出,需要理解 POI API,合理组织数据结构,以及灵活运用单元格合并和样式设置。结合提供的代码文件,你可以进一步研究和学习如何在实际项目中应用这些技术。
"listview带表头(表头固定)"这个主题指的是在ListView中实现一个固定的表头(Header),即使在滚动列表时,表头仍然保持在屏幕顶部,这样可以方便用户始终能看到分类或者列名等关键信息。这种功能在数据分组或需要...
在某些复杂的应用场景下,单层的表头可能无法满足需求,这时就需要用到多层表头(Nested Headers)。在本案例中,"DataGridView实现多层表头"是一个自定义控件,它通过借鉴`TreeView`的原理,将多级分类的表头效果...
2.TcTabelView支持设置多行横向表头(默认2行), 3.可以添加多张表格,每个表格是独立的,它们都有属于自己的自定义表头。 4.表头的右键操作我是自己写的,也可以用原例的方式,不过要复杂一点。 5.每一张表,一个tab,...
首先,让我们从`QTableWidget`开始。`QTableWidget` 是一个即用型的表格控件,提供了完整的表格功能,如添加、删除和编辑单元格等。自定义复杂表头在`QTableWidget`中可以通过创建自定义的`QTableWidgetItem`并设置...
在Windows Presentation Foundation(WPF)中,多表头(MultiHeader)是一种常见需求,它能够帮助用户更好地组织和展示复杂的数据。WPF多表头技术的实现主要涉及到DataGrid控件的自定义,以实现多级分类和多行表头的...
标题“左侧是表头的表格”暗示我们正在讨论一种特殊布局的表格,其中表头位于左侧,这在处理大量列数据时特别有用,因为它允许用户更容易地浏览和理解表格的内容。这种类型的表格常见于数据分析、报表展示以及各种...
总的来说,固定table表头的插件是提高数据展示用户体验的有效工具,它结合了HTML、CSS和JavaScript的技术,通过合理的结构设计和动态定位,实现了在页面滚动时保持表头可见的效果。对于前端开发者来说,理解和掌握...
在开发过程中,有时候我们需要展示复杂的数据结构,这时cxGrid控件的多表头功能就显得尤为重要。cxGrid是Delphi和C++ Builder等RAD Studio环境下常用的一款强大的网格控件,它提供了丰富的自定义功能,包括多级表头...
这包括设置单元格的宽度、边框、内边距等属性,确保合并后的表头布局合理,层次清晰。 4. **数据绑定**:在实现多表头后,别忘了正确地绑定数据源。可以使用`GridView.DataSource = yourDataSource; GridView....
通过合理设置这两个属性,我们可以自由地合并和布局表头单元格。 此外,需要注意的是,HTML中的`<tr>`标签用于创建表格行,`<th>`标签用于创建表头单元格。在代码中,我们直接通过创建`TableHeaderCell`对象来创建...
为解决这个问题,就需要实现一个固定表头的效果,即无论表格如何滚动,表头始终固定在页面的顶部。 要实现这个效果,有几种常用的方法,主要包括使用CSS定位和JavaScript。而根据提供的文件内容,本文介绍了一种...