本文介绍了如何使用分裂短信的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从分割中捕获输出并将其用作动作或与数据库中的数据进行比较

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);

输出为:

pay 
merchant
amount

想要使用支付作为行动和金额来增加数据库中商家的数量

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

推荐答案

您需要定义规则如何将输入转换为数据库上的操作。为了帮助您入门,您可以为每条规则编写 if 这样的语句:

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)
}

这篇关于如何使用分裂短信的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:03