如何将文本拆分为android textview

时间:2015-05-19 16:56:46

标签: android textview

如何通过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那样分裂

示例可以是任何文字:

Lorem Ipsum很简单!印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一台未知的打印机采用了类型的厨房,并将其拼凑成一个类型的样本书。它不仅存在了五个世纪,而且还延续了电子排版,基本保持不变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表格的推出而普及,最近还推出了包括Lorem Ipsum版本在内的Aldus PageMaker等桌面出版软件。

1 个答案:

答案 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;
    }