[Java] 纯文本查看 复制代码
import java.util.Scanner;
public class LetterAndLn {
public static void main(String[] args) {
//测试字符串
String line="access [ˈækses] v.访问 accessed adj.访问的 accessible [ ə kˈses əbl ] adj.可访问的" ;
StringBuilder sb = new StringBuilder(line);
//删音标
while(true){
int start=sb.indexOf("[");
int end=sb.indexOf("]");
if(start==-1){
break;
}else{
sb.delete(start, end+1);
}
}
//输入单词首字母
System.out.println("请输入所处理单词首字母");
Scanner sc=new Scanner(System.in);
String letter=sc.nextLine();
//换行
StringBuilder sb2=new StringBuilder();
while(true){
int start=sb.indexOf(".");
int end = sb.indexOf(letter, start);
if(end==-1){
sb2.append(sb.substring(0));
break;
}else{
sb.insert(end, "\n");
sb2.append(sb.substring(0, end+1));
sb.delete(0, end+1);
}
}
System.out.println(sb2);
}
}