如何通过split()或matcher将文本拆分为android textview。当我分割文本时,我想保持也是分界符。我用过
Sub troubleshoot()
Dim wks As Worksheet, strName As String, pvt As PivotTable, strPvtName As String
For Each wks In Worksheets
strName = wks.Name
For Each pvt In wks.PivotTables
strPvtName = pvt.Name
Debug.Print strName + " / " + strPvtName
Sheets(strName).PivotTables(strPvtName).PivotFields("OrderSubType").ClearAllFilters
Next
Next
Set wks = Nothing
Set pvt = Nothing
End Sub
和
Pattern stuff = Pattern.compile("[\\s]|[\\w+]");
但结果不是我的预期。它没有像android中的textview那样分裂
示例可以是任何文字:
答案 0 :(得分:0)
我想您希望将文本拆分为句子,如下所示
Lorem Ipsum is simply
dummy text of the printing and typesetting industry
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
我使用了String的分割功能,如下所示。
String[] results = source.split("!|\\.|\\?");
希望它有所帮助。
另外,如果你想保留分隔符,下面是样本。
String[] results = source.split("!|\\.|\\?");
int offset = 0;
for(String result : results){
offset += result.length();
// just append the delimiter after the split sub string.
Log.d("", "result = " + result + source.charAt(offset));
offset +=1;
}