Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:43:40+00:00 2026-05-16T23:43:40+00:00

Dear All, I have 2 input string 1)stack,over,flow 2)stack/over,flow,com I would like to print

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:43:41+00:00Added an answer on May 16, 2026 at 11:43 pm

    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:

    s = s.replaceAll("[^a-zA-Z0-9]", "");
    

    If you want to print them one by one:

    s = s.replaceAll("[^a-zA-Z0-9]", "/");
    String[] splitString = s.split("/");
    for(String str:splitString)
    {
       System.out.println(str);
    }
    

    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:

    s = s.replaceAll("[^a-zA-Z0-9]", "/");
    String[] splitString = s.split("/");
    for(int i=0; i<splitString.length(); i++)
    {
       String str = splitString[i];
       System.out.println(str);
    }
    

    Also:

    StringTokenizer is a legacy class
    that is retained for compatibility
    reasons although its use is
    discouraged in new code. It is
    recommended that anyone seeking this
    functionality use the split method
    of String or the java.util.regex
    package instead.

    (from the javadoc)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

dear all, i have a string like this, ...1name: john, 2name: lice, 3name: mike....
dear all..i have a textfield <tr> <td> <td><input type=text id=model_name></td> </td> </tr> and a
dear all..i have a table it looks like: Name version DDX 01 DTX 05
Dear all, my issue is this. I have like the alert box to display
Dear All, i have a txt file like: --start-- jeff --end-- --start-- sophya --end--
Dear all,Now i have this question in my java program,I think it should be
Dear all, I have a question about Facebook Page: ( NOT user profile page,
Dear all, I have a select query that currently produces the following results: DoctorName
Dear All, please help me since I'm newbie in SQL Server. I have a
Dear all expert i had a problem for comparing my string from document.write with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.