Link to home
Start Free TrialLog in
Avatar of jaipur07
jaipur07

asked on

Checking for a Character in String

I have file names in a folder like:
00001.tif, 00002.tif, MS001.tif, AX002.tif etc

I am reading files names using File API...what I want is I want to check if there is any alphabet in file name...
is there any straight forward method on String or String buffer to check that.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Typo:

is there=if there
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Given no numbers in the extension, you could do

boolean valid = fileName.matches("\\d+\\.\\D+");
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Webstorm
Webstorm

>> if there is any alphabet in file name

if (Pattern.matches("[^.]*[A-Za-z].*", filename))
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
boolean valid = fileName.matches("[\\d.]+\\w+");
What's the reason, GranMod?