我如何继续将éëíïñÑ(等)改为对手?即,eeiinN。
我正在考虑使用é - >进行正则表达式匹配; &安培; eacute;并取代&和急/坟;使用空字符串,但我似乎无法找到编码其非数字实体(ê等)的重音的AS3函数。我已经尝试过使用关联数组,la实体[“À”] =“A”;但是AS3似乎不喜欢unicode键。
任何建议都将不胜感激。
谢谢!
答案 0 :(得分:5)
这称为“unicode分解”,所以你可能想要Google。但是,如果您使用的语言不是您自己的语言,请不要这样做。
我知道这个想法对于那些不懂其他语言的英语母语人士来说似乎是合理的,但对于那些字母是字母的人而言,将“W”替换为“VV”,将“d”替换为“cl”更有意义。对于说英语的人而言,“Q”和“O”将会发生。
P.S。既然你问:
你可以遍历执行charCodeAt()
的字符串并在整数上执行关联数组。但我仍然不推荐它。
“Doña”的意思是“女士”,但“dona”的意思是“甜甜圈”。 “De”表示“from”,“dé”表示“give”。等等等等。
它们不仅仅是带有恼人的flyspecks的普通字母,它们实际上与“E”和“F”或“P”和“R”截然不同。
答案 1 :(得分:3)
修正了德语,因为你用“Ae”代表“Ä”,“大江”代表“Ö”等。
/**
* Helper arrays for unicode decomposition
*/
var pattern:Array = new Array();
pattern.push(new RegExp("Š", "g") );
pattern.push( new RegExp("[΅]", "g"));
pattern.push( new RegExp("Ž", "g"));
pattern.push( new RegExp("š", "g"));
pattern.push(new RegExp("[Ϛ]", "g"));
pattern.push( new RegExp("ž", "g"));
pattern.push(new RegExp("[ÀÁÂÃÅ]","g"));
pattern.push( new RegExp("[ÆÄ]","g"));
pattern.push( new RegExp("Ç","g"));
pattern.push( new RegExp("[ÈÉÊË]","g"));
pattern.push(new RegExp("[ÌÍÎÏ]", "g"));
pattern.push( new RegExp("Ð", "g"));
pattern.push( new RegExp("Ñ","g"));
pattern.push( new RegExp("[ÒÓÔÕØ]", "g"));
pattern.push( new RegExp("Ü","g"));
pattern.push( new RegExp("[ÙÚÛ]","g"));
pattern.push( new RegExp("[ŸÝ]", "g"));
pattern.push( new RegExp("Þ", "g"));
pattern.push( new RegExp("ß", "g"));
pattern.push( new RegExp("[àáâãå]","g"));
pattern.push( new RegExp("[æä]","g"));
pattern.push( new RegExp("ç","g"));
pattern.push( new RegExp("[èéêë]","g"));
pattern.push( new RegExp("[ìíîï]","g"));
pattern.push( new RegExp("ð", "g"));
pattern.push( new RegExp("ñ","g"));
pattern.push( new RegExp("[òóôõø]", "g"));
pattern.push( new RegExp("ü","g"));
pattern.push( new RegExp("[ùúû]","g"));
pattern.push( new RegExp("[ýÿ]","g"));
pattern.push( new RegExp("þ", "g"));
var patternReplace:Array = [
"S",
"Oe",
"Z",
"s",
"oe",
"z",
"A",
"Ae",
"C",
"E",
"I",
"D",
"N",
"O",
"Ue",
"U",
"Y",
"Th",
"ss",
"a",
"ae",
"c",
"e",
"i",
"d",
"n",
"o",
"ue",
"u",
"y",
"th"];
/**
* Returns the Unicode decomposition of a given run of accented text.
* @param value The original string
* @return The string without accents
*/
private static function decomposeUnicode(str:String):String
{
for (var i:int = 0; i < pattern.length; i++)
{
str = str.replace(pattern[i], patternReplace[i]);
}
return str;
}
答案 2 :(得分:3)
感谢您的回复。
我来自阿根廷,我们说西班牙语,就像MarkusQ说的那样,删除一个口音可以改变一个词的全部含义。但我还想说,在某些情况下,删除重音更好。
我正在为搜索功能编写脚本,您可以在其中找到名称的人。这些数据来自一个注册表格,人们按照自己喜欢的方式写下自己的名字,即:Lopez /Lópes,Matias /Matías等。
因此,对于AS3,“Lopez”和“López”是不同的单词,当用户搜索“lopez”时,我想在搜索结果中同时使用它们。
这样,我的解决方案是删除所有重音,并在搜索框的文本字段中使用掩码以避免使用重音。我认为这是最好的解决方案,任何人都有更好的主意吗?谢谢!
答案 3 :(得分:2)
private var sdiakA:Array;
private var bdiakA:Array;
private function initReplaceDiacritic(){
var sdiak = "áäčďéěíĺľňóôöŕšťúůüýřžÁÄČĎÉĚÍĹĽŇÓÔÖŔŠŤÚŮÜÝŘŽ";
var bdiak = "aacdeeillnooorstuuuyrzAACDEEILLNOOORSTUUUYRZ";
sdiakA = new Array();
bdiakA = new Array();
for (var i=0;i<sdiak.length;i++)
sdiakA.push(new RegExp(sdiak.charAt(i), "g"))
for (i=0;i<sdiak.length;i++)
bdiakA.push(bdiak.charAt(i))
}
private function replaceDiacritic(string:String){
for (var i:int = 0; i < sdiakA.length; i++)
string = string.replace(sdiakA[i], bdiakA[i]);
return (string)
}
initReplaceDiacritic();
var str = replaceDiacritic("šžřáíéééíčšřčš");
答案 4 :(得分:2)
我希望这对任何人都有用: https://github.com/infralabs/DiacriticsRemove
此类从包含Latin-1 Supplement,Latin Extended-A和Latin Extended-B特殊字符的字符串中删除变音符号。
<强>用法:强>
var specialCharacters:String = "";
specialCharacters+="Latin-1 Supplement\n";
specialCharacters+="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ\n";
specialCharacters+="Latin Extended-A\n";
specialCharacters+="ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ\n";
specialCharacters+="Latin Extended-B\n";
specialCharacters+="ƒǺǻǼǽǾǿ\n";
specialCharacters+="Latin Extended Additional\n";
specialCharacters+="ẀẁẂẃẄẅỲỳ\n";
trace(new DiacriticsRemove().Parse(specialCharacters));
<强>源:强>
Latin-1 Supplement
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
Latin Extended-A
ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžs
Latin Extended-B
ƒǺǻǼǽǾǿ
Latin Extended Additional
ẀẁẂẃẄẅỲỳ
<强>结果:强>
Latin-1 Supplement
AAAAAAAECEEEEIIIIDNOOOOO×OUUUUYTHssaaaaaaaeceeeeiiiidnooooo÷ouuuuythy
Latin Extended-A
AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkĸLlLlLlLlLlNnNnNnnNnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs
Latin Extended-B
fAaAEaeOo
Latin Extended Additional
WwWwWwYy
答案 5 :(得分:0)
另一种选择:
public static function noAccent(source:String):String
{
source = source.replace(/[àáâãäå]/g, "a");
source = source.replace(/[ÀÁÂÃÄÅ]/g, "A");
source = source.replace(/[èéêë]/g, "e");
source = source.replace(/[ËÉÊÈ]/g, "E");
source = source.replace(/[ìíîï]/g, "i");
source = source.replace(/[ÌÍÎÏ]/g, "I");
source = source.replace(/[ðòóôõöø]/g, "o");
source = source.replace(/[ÐÒÓÔÕÖØ]/g, "O");
source = source.replace(/[ùúûü]/g, "u");
source = source.replace(/[ÙÚÛÜ]/g, "U");
source = source.replace(/[ýýÿ]/g, "y");
source = source.replace(/[ÝÝŸ]/g, "Y");
source = source.replace(/[ç]/g, "c");
source = source.replace(/[Ç]/g, "C");
source = source.replace(/[ñ]/g, "n");
source = source.replace(/[Ñ]/g, "N");
source = source.replace(/[š]/g, "s");
source = source.replace(/[Š]/g, "S");
source = source.replace(/[ž]/g, "z");
source = source.replace(/[Ž]/g, "Z");
source = source.replace(/[æ]/g, "ae");
source = source.replace(/[Æ]/g, "AE");
source = source.replace(/[œ]/g, "oe");
source = source.replace(/[Œ]/g, "OE");
return source;
}