Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 信函→;下一个字母和大写元音_Javascript_Regex_String_For Loop_Capitalize - Fatal编程技术网

Javascript 信函→;下一个字母和大写元音

Javascript 信函→;下一个字母和大写元音,javascript,regex,string,for-loop,capitalize,Javascript,Regex,String,For Loop,Capitalize,这段代码似乎仍然不起作用。它不再有错误,但它只返回像这样的空括号{}。它应该将str中的每个字母转换成下一个字母,并将每个元音大写。有什么想法吗 function LetterChanges(str) { str = str.split("");//split() string into array for(var i=0;i<str.length;i++){//for loop that checks each letter if(str[i].match(/[a-y]/i

这段代码似乎仍然不起作用。它不再有错误,但它只返回像这样的空括号
{}
。它应该将
str
中的每个字母转换成下一个字母,并将每个元音大写。有什么想法吗

function LetterChanges(str) { 
str = str.split("");//split() string into array
  for(var i=0;i<str.length;i++){//for loop that checks each letter
    if(str[i].match(/[a-y]/i)){
      str[i]=String.fromCharCode(str[i].charCodeAt(0)+1);
        }else if(str[i].match("z")){
          str[i] = "a";
        }
    if(str[i].match(/[aeiou]/i)){
       str[i] = str[i].toUpperCase();
       }

  }
   str = str.join("");
  //modifies letter by adding up in alphabet
  //capitalizes each vowel
  //join() string


  return str; 
}
function-LetterChanges(str){
str=str.split(“”;//将()字符串拆分为数组

对于(var i=0;i而言,此方法似乎可以简化为对以下对象的几个调用:

或者,也可以调用
.replace
,如下所示:

function LetterChanges(str) { 
    return str.replace(/(z)|([dhnt])|[a-y]/gi, function(c, z, v) {
        c = z ? 'A' : String.fromCharCode(c.charCodeAt(0)+1); 
        return v ? c.toUpperCase() : c; 
    })
}

LetterChanges("abcdefgxyz"); 
//            "bcdEfghyzA"
似乎很好用->,你是怎么用的?
function LetterChanges(str) { 
    return str.replace(/(z)|([dhnt])|[a-y]/gi, function(c, z, v) {
        c = z ? 'A' : String.fromCharCode(c.charCodeAt(0)+1); 
        return v ? c.toUpperCase() : c; 
    })
}

LetterChanges("abcdefgxyz"); 
//            "bcdEfghyzA"