#Changing number tokens into an int from a string and then updating string.
15 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @cunning nova! Please use
/closeor theClose Postbutton 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.
parsing a String to an Integer: Integer.parseInt(yourString)
parsing an Integer to a String: String.valueOf(myInteger)
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
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.
{
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");
}
}
}```
a hash map?
yeah you could use that
Is there anyway that I can read through each token in the string and if a word is recognized it could be changed?
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.
ok I will try those thanks