- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHow can i check wheather ther is a number or special character exist in the string?
for ex. boolean checkstring(String st)
{
}
it will return true if no special charaters found in the String st, otherwise return false. The space is also consider to be the special characters.
thanks in advance for those who try to help me , and all the experts in this site
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: prainPosted on 1999-08-08 at 08:21:42ID: 1247876
There is no straight method in the String class to do the operation you want. Here is a program that will do what you want. In the method isStringContainsSpecialCha racter() below, you may insert the set of special characters you like. I have made a special character string for testing purposes. you may change it to fit into your requirements.
j3802456" ;
Character( testString 1)) " + testString1 + " is a string with " + " + testString1 + " has no special characters.");
Character( testString 2)) " + testString2 + " is a string with " + " + testString2 + " has no special characters.");
racter(Str ing inStr) ;
nnerIndex) )
import java.io.*;
public class CheckIfSpecial
{
public static void main(String args[])
{
String testString1 = "HJHJHJHHKwuw897131048ujdl
String testString2 = "dsklasd%klasjdlasd";
System.out.println("Test 1");
if(isStringContainsSpecial
System.out.println("String
"special characters");
else
System.out.println("String
System.out.println("Test 2");
if(isStringContainsSpecial
System.out.println("String
"special characters");
else
System.out.println("String
}
public static boolean isStringContainsSpecialCha
{
String SpecialCharacters = "$#@%^& !*()?><_-+=~`";
int innerLength = SpecialCharacters.length()
int length = inStr.length();
for (int index = 0; index < length ; index++)
{
for (int innerIndex = 0; innerIndex < innerLength; innerIndex++)
{
if (inStr.charAt(index) == SpecialCharacters.charAt(i
return true;
}
}
return false;
}
}