本文整理汇总了Java中org.apache.commons.lang.StringUtils.indexOfAny方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.indexOfAny方法的具体用法?Java StringUtils.indexOfAny怎么用?Java StringUtils.indexOfAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.StringUtils
的用法示例。
在下文中一共展示了StringUtils.indexOfAny方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBriefFromCommentText
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
protected String getBriefFromCommentText(String commentText) {
int index = StringUtils.indexOf(commentText, '\n');
if (index != -1) {
commentText = StringUtils.substring(commentText, 0, index);
}
index = StringUtils.indexOfAny(commentText, ".!?。!?…");
if (index > 0) {
commentText = StringUtils.substring(commentText, 0, index);
}
if (StringUtils.length(commentText) > 8) {
commentText = StringUtils.substring(commentText, 0, 8) + "…";
}
return commentText;
}
示例2: uncapitalizeShortMessages
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static void uncapitalizeShortMessages(String[] paragraphs) throws Exception {
if (paragraphs.length > 1)
return ;
// Verify whether this is a short message by looking at sentence separators.
int firstIdx = StringUtils.indexOfAny(paragraphs[0], LangDictionary.getInstance().getSentenceSeparators());
if ((firstIdx < 0) || (firstIdx == paragraphs[0].length()))
{
float firstCapRatio = 0.0F;
float allCapsRatio = 0.0F;
RefSupport<Float> refVar0 = new RefSupport<Float>();
RefSupport<Float> refVar1 = new RefSupport<Float>();
ratioOfCapitalizedWords(paragraphs[0],refVar0,refVar1);
allCapsRatio = refVar0.getValue();
firstCapRatio = refVar1.getValue();
if (Math.max(allCapsRatio,firstCapRatio) > MaxCapitalizedRatio)
paragraphs[0] = lowercaseCapitalizedWords(paragraphs[0],1);
}
}
示例3: ratioOfCapitalizedWords
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static void ratioOfCapitalizedWords(String sentence, RefSupport<Float> allCapsRatio, RefSupport<Float> firstCapRatio) throws Exception {
Integer numFirstCapitalEntities = 0;
Integer numAllCapitalEntities = 0;
Integer numLowerCaseEntities = 0;
Integer idx = 0;
while ((idx < sentence.length()) && (idx > 0))
{
String tailOfsentence = sentence.substring(idx);
Integer idxInTail = StringUtils.indexOfAny(tailOfsentence, LangDictionary.getInstance().getWordSeparators());
if (idxInTail == 0)
idx = 0;
else
{
idx=idx+idxInTail;
if (Character.isUpperCase(sentence.charAt(idx + 1)))
{
// just check one next character (for performance reasons)
if ((idx + 2) < sentence.length())
if (Character.isUpperCase(sentence.charAt(idx + 2)))
numAllCapitalEntities++;
else
numFirstCapitalEntities++;
else
numFirstCapitalEntities++;
}
else if (Character.isLowerCase(sentence.charAt(idx + 1)))
numLowerCaseEntities++;
}
}
Integer numAllEntities = numAllCapitalEntities + numFirstCapitalEntities + numLowerCaseEntities;
if (numAllEntities == 0)
{
firstCapRatio.setValue(0.0F);
allCapsRatio.setValue(0.0F);
}
else
{
allCapsRatio.setValue(((float)numAllCapitalEntities / (float)numAllEntities));
firstCapRatio.setValue(((float)numFirstCapitalEntities / (float)numAllEntities));
}
}