Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect non ascii character

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
How do I replace any non ascii characters with a question mark? (?)

We have xml interface to submit incidents in, and it doesn't accept any non ascii characters. I want to replace all non ascii chars with a (?) before submitting?

Anyone knows the search pattern for non ascii char? or Perl function to do such that?

Thanks!
 
Why don't you take a look at what
Code:
$sMyString =~ s/[i]pattern[/i]/[i]replacement[/i]/g
does?
 
I know, just don't know what the pattern should be for non-ascii?

or non english characters....

there're lots of non english characters out there, can't capture them all...
 
I don't know if this is the best way.. but's how I figured out how to do it.

use POSIX qw(isprint);

if (isprint($char)){
print "$char\n";;
}


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
This is probably somewhat more general:

Code:
$nonasc="\x{999}";
$str="$nonasc character $nonasc replaced by ? $nonasc";
$str=~s/\P{IsASCII}/?/g;
print "$str\n";

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top