I want to calculate the value of an integer in a text field while ignoring a string of text that is required before the integer?

Bill Nye

I am making my own assistant program that connects to a bank management program i wrote. I want the user to be able to type into the command field: add $5 or add $10500 or any other amount. How would i calculate the "10500" while ignoring the "add $". The "add $" is used to check what command the user is typing to perform the action. This is what i have so far.

} else if (AssistantFrame.getCommand().equalsIgnoreCase("add $5")) {

        BankBalance.addToBalance(5);

}

This is the code that handles adding the money to the balance.

public static void addToBalance(int balanceAdd){

    Commands.setContinuity(0);

    if(fileBalance.exists()) {

            try {
                loadBalance();
            } catch (FileNotFoundException | UnsupportedEncodingException e) {

            }

            balance += balanceAdd;

            try {
                saveBalance();
            } catch (FileNotFoundException | UnsupportedEncodingException e) {

            }

            AssistantFrame.updateAssistant("Your balance has been succesfully updated.\nYour new balance is - $" + balance);

    } else {

        AssistantFrame.updateAssistant("Sorry, but you don't seem to have a personal\nbank balance created yet.");

    }
fxrbfg

Something like that:

String command = AssistantFrame.getCommand();
int amount = Integer.parseInt(command.replaceAll("[^\\d]",""));
BankBalance.addToBalance(amount);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Find string in text but I also want text before and after the occurance

Check if the integer value of a text field is valid in a switch statement [swift]

Send integer value from text field in Flutter to Go backend

How can I declare that a text field can only contain an integer?

Integer value in text file not changing

I want to store two integer value with an integer key value

Extract Integer Value from String Column with additonal Text in Firebird

"An integer is required" datetime field

How do I make Apex text field required value dynamically

For every integer in a string I want to add an integer on - Python

PostgreSQL text array - query as integer, ignoring non-digits

many integer records or one text field

I want to take the value from text field and show it on the other text field

I have a text file with each line containing an integer. I want to open the text tile and count the number of integers in the file

NumberFormatException while converting a string to an integer value in java

jQuery: issue with converting text to integer (input value)

how to convert a Integer to Text value in Power BI

XSLT: Converting text substring to integer value

Convert string (letter) from file text to integer

Reading String and Integer input from text file

How to convert a text string in an input function into an integer?

Convert string from text file to integer array

similar_text - string / integer comparing

Parsing String read from a text file to Integer

Find if searBar.text contains an integer string?

Remove text from a String Covert to Integer

How do I check for an integer in a text file?

Text is printed in "Behavior on" as decimal but required to print as Integer QML

I want to add a text field by tapping the button