#Changing number tokens into an int from a string and then updating string.

15 messages · Page 1 of 1 (latest)

cunning nova
#

If you add thirty to ten, then result of fifty three is incorrect. This is my example string. my end result should look something like this:
If you add thirty to ten, then result of fifty 3 is incorrect. (I only care about the numbers 0-9)

hollow helmBOT
#

This post has been reserved for your question.

Hey @cunning nova! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

chrome adder
#

parsing a String to an Integer: Integer.parseInt(yourString)
parsing an Integer to a String: String.valueOf(myInteger)

cunning nova
#

If i apply that to my entire string how can I assure that 0-9 are the only numbers effected?

#

For example here:
Only thirty people injured in DC last week and two died
I need the result of
Only thirty people injured in DC last week and 2 died

#

I am having many different strings passed in through a thread.

#

this is kinda where im at now

chrome adder
#

oh that's what you want. Yeah mine is not going to help you with that. I would use a Map of some sorts to store the mappings, for each String a integer value and you can use String#replace to replace these words.

cunning nova
#
{
    public void run(String record)
    {
        try 
        {
            String recordDiscover = record.replace("*",""); // remove *
            recordDiscover = recordDiscover.trim();

            List<String> allowedStrings = Arrays.asList("zero","one","two","three","four","five","six","seven","eight","nine");
        
    
            
            System.out.println("Discover - Section 3 is: " + recordDiscover + " - passwd is: " + finalResult );
            Thread.sleep(1000);
        }
        catch (Exception e) 
        {
            System.out.println("Exception is caught");
        }
    }
}```
chrome adder
#

yeah you could use that

cunning nova
#

Is there anyway that I can read through each token in the string and if a word is recognized it could be changed?

chrome adder
#

Combination out of StringTokenizer and StringBuilder would get you the result you need. But just using the replace method defined in String should get your expected results.

cunning nova
#

ok I will try those thanks