I would like to know how to take a selected Item string ("Allen Hall: $1,500 per semester") from one combobox and another selected Item string ("7 meals per week: $650 per semester") from another combobox and have the output to be ($2,150) the total of the two strings added together?

Recommended Answers

All 4 Replies

extract numbers from text

using what method?

Ok this is what im working with so far...

import java.util.*;

public class StringSplit 
{ 
	public void doit() 
		{ 
			String str = "Allen Hall: $1,500 per semester"; 
			String [] temp = null; 
			temp = str.split(":"); 
			dump(temp); 
			String [] temp1 = null; 
			temp1 = str.split(" "); 
			dump(temp1);
		} 
			
			public void dump(String []s) 
			{ 
				for (int i = 2; i < s.length ; i++) 
				{ 
					System.out.println(s[i]); 
			   } 
			} 
		
			
			public static void main(String args[]) throws Exception
			{ 
				StringSplit ss = new StringSplit(); 
				ss.doit(); 
			}
		}

this is my output
$1,500
per
semester

How do I get it to just output the $1500?

The for loop should start at i=0. Print the all elements of the array. You call the dump twice with 2 different calls of the split method. Print the data of the array and then decide which split call suits you better and which element of the array holds the $1500.

Try this:

public void dump(String []s) { 
  System.out.println("Calling dump");
  for (int i = 0; i < s.length ; i++) { 
   System.out.println(i+":"+s[i]); 
  } 
  System.out.println("------------");
}

And see what gets printed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.