我有两个文本文件data.txt和template.txt.我读取并拆分data.txt中的数据并将它们存储为数组.我的问题是将这些数据与template.txt文件一起使用,找到'$'符号并使用随后的数字作为customerData中数组的指示符.
data.txt中
Public|Jane|Q|Ms.|600|Maple Street|Your Town|Iowa|12345
Penner|Fred|R|Mr.|123|that Street|Winnipeg|MB|R3T 2N2
Gardner|Mark|E|Mr.|76|The Avenue|Toronto|ON|M5W 1E6
Acton|Hilda|P|Mrs.|66|What Blvd|Winnipeg|MB|R3T 2N2
Run Code Online (Sandbox Code Playgroud)
template.txt
Welcome back, $1!
We hope that you and all the members
of the $0 family are constantly
reminding your neighbours there
on $5 to shop with us.
As usual, we will ship your order to
$3 $1 $2. $0
$4 $5
$6, $7 $8
Run Code Online (Sandbox Code Playgroud)
输出应该是这样的:
Welcome back, Jane!
We hope that you and all the members
of the Public family are constantly
reminding your neighbors …Run Code Online (Sandbox Code Playgroud) 作为项目/作业的学生,我一直在编写我的链表数据结构,我想知道"真实世界"开发人员是否必须编写自己的链表DS或使用任何已提供的链表Java文档中的对象.哪种情况更好?在什么情况下?
我是一个java新手,我很想知道如何分割一个以逗号开头的字符串,然后在结尾处跟着一个冒号.这种字符串的一个例子是?
-10,3,15,4:38
5,15,8,2:8
Run Code Online (Sandbox Code Playgroud)
可能是这样吗?
sections = line.split(",");
tokens = sections[3].split(":");
Run Code Online (Sandbox Code Playgroud)
或者甚至可以将文件读取的行分成两次?
tokens = line.split(",");
tokens = line.split(":");
Run Code Online (Sandbox Code Playgroud)
我也尝试了这个,但它给了我一个ArrayOutOfBound错误
tokens = line.split("[,:]");
Run Code Online (Sandbox Code Playgroud)
任何贡献将不胜感激.
我正在看这本书programming pearls by Jon Bentley,我遇到了这个问题。
给定一个很长的字节序列(例如,数十亿或数万亿),如何有效地计算 1 位的总数?(即序列中有多少位被打开)
我见过的大多数解决方案都不会被认为是有效的。您认为如何有效解决这个问题?