用相应的字母数字替换最后一个字母? [英] Replace last letter with the corresponding alphabet number?

查看:161
本文介绍了用相应的字母数字替换最后一个字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用重命名应用程序使用 Javascript 进行各种操作,我正在尝试替换 最后一个字母某些文件名>相应的字母数字。例如,从文件名A A 到文件名A 1 ,从文件名A B 到文件名A 2 等等



我的尝试:



此应用程序默认为我提供此功能...

Using a renamer application which is doing various stuff using Javascript, I am trying to replace the last letter of some filenames, to the corresponding alphabet number. For example, from "Filename AA" to "Filename A1", from "Filename AB" to "Filename A2" etc.

What I have tried:

This application gives me this function by default...

function(index, item) { }

我必须在那里编写我的代码,它看起来像这样......

And I have to write my code in there, which could looks like this...

function(index, item) {return item.newBasename...etc}.

根据以下示例,我该怎么做?

Based on this example below, how can I do this?

function(index, item) {
    return item.newBasename.replace(???);
}

推荐答案

根据您的帖子,您可以更新代码以使用以下示例。下面的示例将使用相应的字母数字替换字符串的最后一个字符。



Based on your post, you can update the code to use the following example. The below example will replace the last character of a string with a corresponding alphabet number.

var s = "Filename AA";
s = s.replace(/\w([^\w]*)


/, 1);
console .log(s); // 文件名A1

var s = 文件名A1;
s = s.replace(/ \ w([^ \w] *)
/, "1"); console.log(s); //Filename A1 var s = "Filename A1"; s = s.replace(/\w([^\w]*)


/, B);
console .log(s); // 文件名AB
/, "B"); console.log(s); //Filename AB


这篇关于用相应的字母数字替换最后一个字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆