How to determinate if an character in a string

A

ad

I want to determinate if there are alphabets in a string. (not all number)
How can I do?
 
J

Jon Shemitz

I want to determinate if there are alphabets in a string. (not all number)
How can I do?

If you really want to simply find if a string has non-numeric
characters, you can do

Regex.IsMatch("[^0-9]", StringToTest);
 
D

Dave Sexton

Hi Jon,

(Arguments are not in the correct order ;)

And just in case the OP wants to ensure that only alpha characters appear in
the entire string, excluding all white-space, numbers and symbols (but
allowing a zero-length string):

bool alphaOnly = Regex.IsMatch(@"^\p{L}*$", str);

--
Dave Sexton

Jon Shemitz said:
I want to determinate if there are alphabets in a string. (not all
number)
How can I do?

If you really want to simply find if a string has non-numeric
characters, you can do

Regex.IsMatch("[^0-9]", StringToTest);

--

.NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.
 
D

Dave Sexton

.... and I put the arguments in the wrong order as well :p

bool alphaOnly = Regex.IsMatch(str, @"^\p{L}*$");

--
Dave Sexton

Dave Sexton said:
Hi Jon,

(Arguments are not in the correct order ;)

And just in case the OP wants to ensure that only alpha characters appear
in the entire string, excluding all white-space, numbers and symbols (but
allowing a zero-length string):

bool alphaOnly = Regex.IsMatch(@"^\p{L}*$", str);

--
Dave Sexton

Jon Shemitz said:
I want to determinate if there are alphabets in a string. (not all
number)
How can I do?

If you really want to simply find if a string has non-numeric
characters, you can do

Regex.IsMatch("[^0-9]", StringToTest);

--

.NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.
 
A

ad

If I want to determinate if there are 2 alphabets in a string at least
"12ab34", "123a5bc", "a123c4" is ok, but "2345", 2a35" is not ok.
How can I do?
 
D

Dave Sexton

Hi,

You can use a Regular Expression, as Jon posted originally, but with a
different pattern.

"Regular Expression Language Elements"
http://msdn2.microsoft.com/en-us/library/az24scfc.aspx

To match a string containing at least 2 characters of the alphabet at any
position, you can use the following expression:

bool atLeast2Alpha = Regex.IsMatch(input, @"\p{L}.*\p{L}");

Add a using directive at the top of your code file:

using System.Text.RegularExpressions;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top