Dear All,
I have 2 input string 1)stack,over,flow 2)stack/over,flow,com
I would like to print only strings(without special char)from the above 2 input
for 1st input i used below function but for 2nd input i dont know how to process it.Pls give me solution.
st = new StringTokenizer("stack,over,flow", ",");
while (st.hasMoreTokens())
{
String token = st.nextToken();
System.out.println("token = " + token);
}
output:
stack
over
flow
Can you define what you mean by a special char? Do you mean “only alphanumeric characters”?
If you want to remove all possible special characters and leave only alphanumeric characters, then you can use the following:
If you want to print them one by one:
EIDT:
Since you asked: the above code uses the enhanced for loop (also called the for-each loop) introduced by java 5.
Using the ‘normal’ for loop, this is:
Also:
(from the javadoc)