package com.example;
import com.github.promeg.pinyinhelper.Pinyin;
import javax.net.ssl.SSLServerSocket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Demo {
public static void main(String[] args) {
long begin = System.currentTimeMillis();
for (int i = 0; i < 5000000; i++) {
getTimes();
}
long end = System.currentTimeMillis() - begin;
System.out.println(end);
}
private static void getTimes() {
String before = "星期三"; // xingqisan
String after = "哈哈哈";
String newText = "";
String beforePinyin = Pinyin.toPinyin(before, "");
List<String> textList = new ArrayList<>(Arrays.asList("今天星期五","明天星期三"));
for (String text : textList) {
String Item = Pinyin.toPinyin(text, "");
if (!Pinyin.toPinyin(text, "").contains(beforePinyin)) {
continue;
}
String[] split = text.split("[、,。;?!,.;?!]");
Pinyin.toPinyin(text, "");
// 最后一个词的开始索引
for (int i = 0; i <text.length()-before.length() + 1; i++) {
for (String str : split) {
String substring = str.substring(i, i+before.length());
String pinyin = Pinyin.toPinyin(substring, "");
if (pinyin.contains(beforePinyin)) {
newText = text.replace(substring, after);
}
}
}
}
//System.out.println(newText);
}
}
0108-sk
最新推荐文章于 2024-11-12 21:14:07 发布