我在cygwin上的bash安装没有正确处理重音字母.我尝试添加
set input-meta on # to accept 8-bit characters
set output-meta on # to show 8-bit characters
set convert-meta on # to show it as character, not the octal representation
Run Code Online (Sandbox Code Playgroud)
我的输入rc,但这还不太有用.的确,如果我输入
$ echo ù
Run Code Online (Sandbox Code Playgroud)
然后在我按下输入之前它会自动更改为
$ echo \303
Run Code Online (Sandbox Code Playgroud)
虽然输出是正确的,但我得到了
$ echo \303
ù
Run Code Online (Sandbox Code Playgroud)
对于任何其他重音字母,我得到相同的结果.通常虽然我使用的是非意大利语键盘,但我使用autohotkey带有重音字母的撇号替换字母.在这种情况下,重音字母被替换为a \302,并且根据字母打印垃圾:打印a 3y表示a ù,a ¢表示an ò,而不打印其他内容.
我怎样才能让这一切变得有意义?
编辑:我的语言环境设置,cygwin版本和终端如下
$ uname -a
CYGWIN_NT-6.1-WOW64 ferdi-Asus 1.7.17(0.262/5/3) 2012-10-19 14:39 i686 Cygwin
$ locale
LANG=it_IT.UTF-8
LC_CTYPE="it_IT.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="it_IT.UTF-8"
LC_COLLATE="it_IT.UTF-8"
LC_MONETARY="it_IT.UTF-8"
LC_MESSAGES="it_IT.UTF-8"
LC_ALL=
$ tty …Run Code Online (Sandbox Code Playgroud) 如何使用echo 编写非ASCII字符?是否有转义序列,例如\012或类似的东西?
我想使用以下方法将ASCII字符附加到文件:
echo ?? >> file
Run Code Online (Sandbox Code Playgroud) 我试图通过正则表达式传递大量随机html,我的Python 2.6脚本对此感到窒息:
UnicodeEncodeError:'ascii'编解码器无法编码字符
我追溯到这个词末尾的商标上标:Protection™ - 我希望将来会遇到其他类似的人.
是否有处理非ascii字符的模块?或者,在python中处理/转义非ascii内容的最佳方法是什么?
谢谢!完整错误:
E
======================================================================
ERROR: test_untitled (__main__.Untitled)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python26\Test2.py", line 26, in test_untitled
ofile.write(Whois + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2122' in position 1005: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
完整脚本:
from selenium import selenium
import unittest, time, re, csv, logging
class Untitled(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox", "http://www.BaseDomain.com/")
self.selenium.start()
self.selenium.set_timeout("90000")
def test_untitled(self):
sel = self.selenium
spamReader = csv.reader(open('SubDomainList.csv', 'rb'))
for row in …Run Code Online (Sandbox Code Playgroud) 我已经通过Stackoverflow上的其他问题阅读了,但仍然没有更接近.对不起,如果已经回答了这个问题,但我没有得到任何建议.
>>> import re
>>> m = re.match(r'^/by_tag/(?P<tag>\w+)/(?P<filename>(\w|[.,!#%{}()@])+)$', '/by_tag/xmas/xmas1.jpg')
>>> print m.groupdict()
{'tag': 'xmas', 'filename': 'xmas1.jpg'}
Run Code Online (Sandbox Code Playgroud)
一切都很好,然后我尝试用挪威字符(或更像unicode)的东西:
>>> m = re.match(r'^/by_tag/(?P<tag>\w+)/(?P<filename>(\w|[.,!#%{}()@])+)$', '/by_tag/påske/øyfjell.jpg')
>>> print m.groupdict()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'groupdict'
Run Code Online (Sandbox Code Playgroud)
如何匹配典型的unicode字符,例如øæå?我希望能够在上面的标签组和文件名的标签组中匹配这些字符.
python regex unicode non-ascii-characters character-properties
我试图找到我的本地系统分配给箭头键的值,特别是在Python中.我使用以下脚本执行此操作:
import sys,tty,termios
class _Getch:
def __call__(self):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def get():
inkey = _Getch()
while(1):
k=inkey()
if k!='':break
print 'you pressed', ord(k)
def main():
for i in range(0,25):
get()
if __name__=='__main__':
main()
Run Code Online (Sandbox Code Playgroud)
然后我运行了脚本,然后点击向上右下方,这给了我这个输出:
$ python getchar.py
you pressed 27
you pressed 91
you pressed 65
you pressed 27
you pressed 91
you pressed 66
you pressed 27
you pressed 91
you pressed 67
you pressed …Run Code Online (Sandbox Code Playgroud) 在Delphi 2007中是否有例程可以根据区域设置(代码页)将ANSI表(> 127)的高范围内的字符转换为纯ASCII(<= 127)中的等效字符?
我知道有些字符不能很好地翻译,但大多数字符都可以,尤其是.在192-255范围内:
delphi ascii character-encoding delphi-2007 non-ascii-characters
我正在使用基于AJAX的查找来查找用户在文本框中搜索的名称.
我假设数据库中的所有名称都将被音译为欧洲字母表(即没有西里尔语,日语,中文).但是,名称仍将包含重音字符,例如ç,ê甚至č和ć.
像"Micic"这样的简单搜索与"Mičić"不匹配 - 而且用户的期望是它会.
AJAX查找使用正则表达式来确定匹配.我已使用此函数修改了正则表达式比较,以尝试匹配更多重音字符.但是,它有点笨拙,因为它没有考虑到所有角色.
function makeComp (input)
{
input = input.toLowerCase ();
var output = '';
for (var i = 0; i < input.length; i ++)
{
if (input.charAt (i) == 'a')
output = output + '[aàáâãäåæ]'
else if (input.charAt (i) == 'c')
output = output + '[cç]';
else if (input.charAt (i) == 'e')
output = output + '[eèéêëæ]';
else if (input.charAt (i) == 'i')
output = output + '[iìíîï]';
else if (input.charAt (i) == 'n')
output = …Run Code Online (Sandbox Code Playgroud) 我正在尝试将编码为OEM-866(西里尔语字符集)的CSV导入到Windows上的R中.我还有一份已经转换为UTF-8无副BOM的副本.一旦指定了编码,这两个文件都可以被我的系统上的所有其他应用程序读取.
此外,在Linux上,R可以使用指定的编码读取这些特定文件.我也可以在Windows上读取CSV如果我没有指定"fileEncoding"参数,但这会导致文本不可读.当我在Windows上指定文件编码时,对于OEM和Unicode文件,我总是会遇到以下错误:
原始OEM文件导入:
> oem.csv <- read.table("~/csv1.csv", sep=";", dec=",", quote="",fileEncoding="cp866") #result: failure to import all rows
Warning messages:
1: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
invalid input found on input connection '~/Revolution/RProject1/csv1.csv'
2: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
number of items read is not a multiple of the number of columns
Run Code Online (Sandbox Code Playgroud)
没有BOM文件导入的UTF-8:
> unicode.csv <- read.table("~/csv1a.csv", sep=";", dec=",", quote="",fileEncoding="UTF-8") #result: failure to import all row
Warning messages:
1: In …Run Code Online (Sandbox Code Playgroud) 我在R中使用UTF-8编码包含一些包含重音的字符串.例如
string="Hølmer"或string="Elizalde-González"
R中是否有任何不错的功能可以替换这些字符串中的重音符号?我在这里看到了PHP中的一些解决方案,但是我如何在R中执行此操作?
例如PHP代码
$unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' );
$str = strtr( …Run Code Online (Sandbox Code Playgroud) 我有"utf8 - UTF-8 Unicode"中的模式作为charset和"utf8_spanish_ci"的排序规则.
所有内部表都是InnoDB,具有与上述相同的字符集和校对.
问题出现了:
像查询一样
SELECT *
FROM people p
WHERE p.NAME LIKE '%jose%';
Run Code Online (Sandbox Code Playgroud)
我得到83个结果行.我应该有84个结果,因为我知道.
改变地点:
WHERE p.NAME LIKE '%JOSE%';
Run Code Online (Sandbox Code Playgroud)
我得到完全相同的83行.使用JoSe,Jose,JOSe等组合.报告所有相同的83行.
问题来自游戏中的重音.如果:
WHERE p.NAME LIKE '%josé%';
Run Code Online (Sandbox Code Playgroud)
我没有结果.0行.
但如果我这样做:
WHERE p.NAME LIKE '%JOSÉ%';
Run Code Online (Sandbox Code Playgroud)
我得到一个结果行,所以1行.这是唯一一个带有"jose"和大写字母的行.
我已经尝试过josÉ,或JoSÉ或我做的任何组合,只要重音符号保持大写或不大写,因为它确实存储在数据库中并且它仍然返回唯一的行.如果我突然改变"é"为"é",无论我用JOSE中的大小写做什么组合,它都不返回任何行.
所以结论:
我想要的是?
类似的解决方案COLLATION在LIKE不为我工作的,不知道为什么?
我能做什么?
提前致谢!
编辑:
如果我喜欢这样的话:
WHERE p.NAME LIKE '%jose%' COLLATE utf8_general_ci;
Run Code Online (Sandbox Code Playgroud)
我收到错误:
COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'latin1'
我也改变了列上所有可能的排序规则!
如果我做了类似的事情:
WHERE p.NAME LIKE _utf8 '%jose%' COLLATE utf8_general_ci;
Run Code Online (Sandbox Code Playgroud)
报告了相同的83行,好像我什么都没做......