我在学中文。我有一个带有光学字符识别器的iPhone应用程序,它可以捕获这种格式的语音列表:(字符TAB发音TAB定义)
yin2hui4淫秽淫秽;淫秽;淫秽 wang3zhan4网站TAB网站 zhuan1xiang4专项TAB .指定用途
但是,我使用的闪存卡应用程序需要这样的格式:(字符新线读音,纽线定义)
淫秽 yin2hui4 淫秽的;淫荡的 网站 wang3zhan4 网站 专项 zhuan1xiang4 attr。指定用途
我只懂一点爪哇。如何将第一种格式转换为第二种格式?
发布于 2013-07-02 10:39:47
显然,我们不想做你的家庭作业。但我们也不想让你搁浅。
我留下了很多东西,下面只是一个看起来像Java的伪代码。你可以从这里开始。
FileReader reader = ... // open the file reader using the input file
FileWriter writer = ...// open a file for writing output
while(the stream doesn't end) { // provide the condition, as must be
String line = ... // read a line from the reader
String character = line.substring(0, line.indexOf("\t")),
pronounciation = line.substring(character.length() -1).substring(line.indexOf("\t", character.length()),
definition = line.substring(line.lastIndexOf("\t")); // Obviously, this isn't accurate.... you need to work around this.
writeLineToFile(character)
writeLineToFile(pronounciation)
writeLineToFile(definition)
}
close the reader and writer
发布于 2013-07-02 10:39:13
尽管它看起来像个练习。但理想情况下你可以做到。
示例代码
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class Test {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String path = "C:/test.txt";
// TODO Auto-generated method stub
File file = new File(path);
String string = FileUtils.readFileToString(file);
String finalString = string.replaceAll("\t", "\n");
FileUtils.write(file, finalString);
}
}
文件现在看起来就像
淫秽
yin2hui4
obscene; salacious; bawdy
网站
wang3zhan4
website
专项
zhuan1xiang4
attr. earmarked
https://stackoverflow.com/questions/17422628
复制相似问题