2017-03-23 1 views
-1

最初の段落文字をキャプチャしてstringに格納する必要があります。段落に300文字以上含まれている場合は、300個しかキャプチャする必要がありません。最初の段落をキャプチャしてJavaのStringに格納する方法

同じコードを書きましたが、段落に300が含まれている場合はキャプチャし、それ以外の場合は2番目の段落からキャプチャを試みます。私は最初の段落だけをキャプチャする必要があります。

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文字で取り込む方法を教えてください。

+0

段落は「Rの\ n個の\ r \ nを\」であるならば、300よりも長い場合には、この –

+0

に基づいてちょうど 'split'が、その後 –

+0

をサブストリングするあなたは、単に最初の300をサブストリングできない理由何らかの理由がある(または段落の文字数は少ないですか? –

答えて

-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)); 
関連する問題