-1

我必须捕获第一段字符并且需要存储在字符串中。如果段落包含超过 300 个字符,我们只需要捕获 300 个。

我写了一些代码来做同样的事情,但它会捕获段落是否包含 300,否则它会尝试从第二段中捕获。我只需要捕获第一段。

String description = "Getting value from some paragraph as description";
if(StringUtils.isNotEmpty(description) && description  != null && description.length()>=300){
int maxValue = 300;
description  = description .substring(0, maxValue);
schema.add(description );
} else {
if(StringUtils.isNotEmpty(description) && description  != null && description.length()>=0){
schema.add(description);
}

谁能建议我如何用 300 个字符捕捉第一段。

4

1 回答 1

-1

尝试这个。

String description = "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.";
System.out.println(description.substring(0, 300));
于 2017-03-23T04:44:10.583 回答