替换文件名中的字符 ionic5 Angular IOS
我在 ionic5 Angular IOS 中使用此代码将 é 替换为 %CC%81 但它不起作用
const regex = /é/gi;
fileName = fileName.replace(regex,"%CC%81");
I use this code in ionic5 angular IOS to replace é with %CC%81 but it's not work
const regex = /é/gi;
fileName = fileName.replace(regex,"%CC%81");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个新的
RegExp
,如下所示:const regex = new RegExp(/é/gi);
编辑:经过仔细检查,我注意到您的字母尝试替换的内容与您的
la péériodeé
字符串中的不相同,即使它们对您来说看起来相同。因此,您需要在正则表达式中添加两种类型的“e”,例如:const regex = new RegExp(/é|é/gi);
如果这没有按您预期的方式编译,则它可能是由于字母失去了其特征,所以为了安全起见 - 您可以复制第一个“e”(la péériodeé)并将其粘贴到正则表达式中的第一个位置,然后复制并粘贴第二个“e” (la péériodeé)。
You need to create a new
RegExp
as in:const regex = new RegExp(/é/gi);
EDIT: After closer examination, I noticed that the letters you're trying to replace are not the same in your
la péériodeé
string, even if they look the same to you. So you'll need to add both types of 'e' in your regex, like:const regex = new RegExp(/é|é/gi);
If this does not compile as you expect, it might be due to letters losing their characteristics, so to be safe - you can just copy your first 'e' (la péériodeé) and paste it at the first position in regex, then copy and paste the second 'e' (la péériodeé).