2015-03-18 20 views
-1

即时尝试将字符串的第一个字母更新为大写,请注意,我只允许使用.substr和.length转换它。没有正则表达式或任何东西。使用.substr将第一个字母更新为大写

这是正确的方法/语法来做到这一点?

e1 = prompt("Please enter your first name", "andrew"); 

e1.toUpperCase(e1.substr(e1.length - e1.length,0)); 
+1

你真的可以使用谷歌这种东西。这是相当普遍的 – 2015-03-18 21:16:24

回答

0

正则表达式的一切!

e1 = prompt("Please enter your first name", "andrew"); 
e1.replace(/^\w/, function(t){ return t.toUpperCase() }) 
+0

不允许使用正则表达式,我只能使用substr /和.length 我的班级和作业限制的一部分 – 2015-03-18 21:20:12

+0

@AndrewBarsoom'e1 = e1.substr(0,1).toUpperCase()+ e1。 SUBSTR(1);' – 2015-03-18 21:23:44

相关问题