View Single Post
  #1 (permalink)  
Old 11-12-2007, 05:06 AM
toad toad is offline
Member
 
Join Date: Oct 2007
Posts: 11
toad is on a distinguished road
Extracting words from a string using delimiters
I need to write a program that extracts words from a string using spaces and punctuation marks as delimiters. Enter the string from an input dialog box.

Here is my code so far.
Code:
import java.util.*; import javax.swing.JOptionPane; public class Exercise8_18 { /**Main method*/ public static void main(String[] args) { // Receive text entered from the dialog box String s = JOptionPane.showInputDialog( "Enter a sentence using punctuation:"); String delims = "[\\s\\p{Punct}]+"; String[] tokens = str.split(delims); System.out.println("The extracted words are:"); System.exit(0); } }
Here is the error message I am getting:
Code:
Exercise8_18.java:11: cannot find symbol symbol : variable str location: class Exercise8_18 String[] tokens = str.split(delims); ^ 1 error sprouts-computer:~/Desktop sprout$
Am I close or way off base?

Last edited by toad : 11-12-2007 at 05:06 AM. Reason: typo
Reply With Quote
Sponsored Links