How to use output from a splited sms [closed]

馋奶兔 提交于 2020-01-06 14:26:30

问题


How can l capture the output from a split and use it for example as an action or comparing with data in the database

String myString =  (msg.getText());

String[] a = myString.split("\\*");

for (String b : a)
    System.out.println(b);

the output is:

pay 
merchant
amount

want to use pay as an action and amount to increase the amount of the merchant in the database


回答1:


You will need to define the rules for how to translate the input into an action on the database. To get you started, you can write if statements like this for each rule:

if (a.length == 3 && a[0] == "pay" && a[1] == "merchant")
{
    double amount = Double.parseDouble(a[2]);
    // connect to database and add amount to the merchant
    // UPDATE [AmountTable] SET [Amount] = [Amount] + ?
    // WHERE [Type] = 'Merchant' (or whatever the logic is)
}



回答2:


String [] message_parts = message.split("#");
// check format
String pay = message_parts[0];
String merchant = message_parts[1];
String amount_string = message_parts[2];


来源:https://stackoverflow.com/questions/10325944/sms-payment-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!