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.
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:
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?