473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Detec nonascii in a string

Hello,

How do I detect non-ascii letters in a string?
I want to detect the condition that a string have a letter that is not
here: string.ascii_letters

Best regards,
SB.

--
Bioinformatics news: http://www.bioinformatica.info
Lriser: http://www.linspire.com/lraiser_success.php?serial=318
Feb 23 '06 #1
4 1633
On Thu, 23 Feb 2006 12:32:35 -0300, Sebastian Bassi wrote:
Hello,

How do I detect non-ascii letters in a string?
I want to detect the condition that a string have a letter that is not
here: string.ascii_letters


for c in some_string:
if c not in string.ascii_letters:
raise ValueError("Non-ascii value!!!")

Instead of raising an error, you can take whatever action you prefer:

for c in some_string:
if c not in string.ascii_letters:
print "Character '%s' is non-ascii." % repr(c)

Or turn it into a function:

def isascii(s):
for c in some_string:
if c not in string.ascii_letters:
return False
return True
--
Steven.

Feb 23 '06 #2
Sebastian Bassi wrote:
Hello,

How do I detect non-ascii letters in a string?
I want to detect the condition that a string have a letter that is not
here: string.ascii_letters

Best regards,
SB.

--
Bioinformatics news: http://www.bioinformatica.info
Lriser: http://www.linspire.com/lraiser_success.php?serial=318

see:

http://groups.google.com/group/comp....1319757576f45/

eg. ord(max(string)) < 128 ( Scott David Daniels ).
Gerard

Feb 23 '06 #3
Sebastian Bassi wrote:
Hello,

How do I detect non-ascii letters in a string?
I want to detect the condition that a string have a letter that is not
here: string.ascii_letters


"äöü".decode("ascii")

should do the trick -- you get an UnicodeError when there is anything ascii
can't encode.

Diez
Feb 23 '06 #4
On 2/23/06, Diez B. Roggisch <de***@nospam.web.de> wrote:
"äöü".decode("ascii")
should do the trick -- you get an UnicodeError when there is anything ascii
can't encode.


Thank you. This is good enought for me.
Best regards,
SB.

--
Bioinformatics news: http://www.bioinformatica.info
Lriser: http://www.linspire.com/lraiser_success.php?serial=318
Feb 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
4
by: Elaine Jackson | last post by:
What's the trick for using nonascii symbols in string literals?
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
9
by: Lans | last post by:
I have a string that I need to tokenize but I need to use a string token see example i am trying the following but strtok only uses characters as delimiters and I need to seperate bu a certain...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
1
by: Thomas | last post by:
It looks like the String.replace doesn't work in IE6.1. Anyone else has the same problem. I am using newest service package of IE and Win2K. Thanks
37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.