在我的Android应用程序 在消息中,如果我给消息“嗨#名称,欢迎您的用户名:#用户名和密码:#密码”和消息#名称,#用户名,#密码将被替换其值从IAM csv文件 读,它应该发送消息的例子:“喜的Praveen,欢迎您的用户名:neevarp和密码:12345” 和这些价值观是从CSV。而搜索我得到了一些链接在Android中的命名占位符
Named placeholders in string formatting
Map<String, String> values = new HashMap<String, String>();
values.put("value", x);
values.put("column", y);
StrSubstitutor sub = new StrSubstitutor(values, "%(", ")");
String result = sub.replace("There's an incorrect value '%(value)' in column # %(column)");
但在android
StrSubstitutor 类是不存在我想是这样,有没有办法实现这个
这里是我从CSV读数值的代码,并通过替换发送消息占位
public void sendingSms(String message, String file_path) {
File file = new File("", file_path);
// Read text from file
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
int iteration = 0;
while ((line = br.readLine()) != null) {
if (iteration != 0) {
StringBuilder text = new StringBuilder();
text.append(line);
String[] contact = text.toString().split(",");
String phoneNumber = contact[4];
String name = contact[1];
String username = contact[2];
String password = contact[3];
//here i have to replace place holders with name,username,password values
//message.replace("#name", name);
//message.replace("#user", username);
Toast.makeText(Message.this, "" + message,
Toast.LENGTH_SHORT).show();
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null,
null);
}
iteration++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
嘿Alex Fu,我已经添加了我的代码,我不确定它是如何有用的,可以请你解释一下,在我的情况下它将如何有用 – praveen