我正处于文件I / O的初级阶段,所以我不知道如何只取一行的一些部分来检索输入的某些方面,例如firstName,LastName,Address和什么不是。我只做了一些非常初学的事情,例如整行,并将其输出到文本文件中。第一个文本文件包含此类信息以用作输入文件:
FirstNameFXO|LastFXO|2510 Main Street|Suite 101D|City100|GA|72249|$280.80
FirstNamePNR|LastPNR|396 Main Street|Suite 100A|City102|GA|24501|$346.01
FirstNameXZU|LastXZU|2585 Main Street|Suite 107C|City101|GA|21285|$859.40
FirstNameHWD|LastHWD|1019 Main Street|Suite 102D|City105|GA|28273|$317.12
FirstNameGHP|LastGHP|2097 Main Street|Suite 109B|City106|GA|72621|$279.28
这是输出应该是什么样的,解决方案是否会创建一个if语句,每当出现一列时都会使用该语句?所以在伪代码形式:
if(输入读取“|”){
检索输入的那部分
}
这就是第二个文本文件应该与我一起用第一个文件的输入替换每个组件。我想弄清楚解决方案是什么。
Dear FirstNameXMI LastXMI,
Our records shows unpaid balance of $724.78 that is over 120+ days old.
The balance due is now. If the balance is not fully paid in ten days
(by 3/27/2017), we will have to inform the collection agent for outstanding
balance plus %10 processing fee that increases total amount to $797.26.
If you have any questions or like to discuss a payment plan, please do
not hesitate our office at 555-555-5555.
答案 0 :(得分:1)
要解析每行的值,您可以使用split()
。
String str = "FirstNameFXO|LastFXO|2510 Main Street|Suite 101D|City100|GA|72249|$280.80";
String[] values = string.split("|");
String firstName = values[0]; // FirstNameFXO
String lastName = values[1]; // LastFXO
然后,你的来信可以从这样的事情开始:
String letter = "Dear " + firstName + " " + lastName + ",";