题解 | #替换空格#
替换空格
http://www.nowcoder.com/practice/0e26e5551f2b489b9f58bc83aa4b6c68
1.字符串的方法
string.length
string.charAt(1)
2.字符串字符的扩展
1.另一种思路,将字符串转换为数组
console.log([..."ab☺de"]); // ["a", "b", "☺", "d", "e"]
2.空格的几种表示方法?
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return string字符串
*/
function replaceSpace( s ) {
let replaceResult = "";
// write code here
for(let i = 0; i < s.length; i++) {
if(s.charAt(i) == " ") {
replaceResult += "%20";
}
else {
replaceResult += s.charAt(i);
}
}
return replaceResult;
}
module.exports = {
replaceSpace : replaceSpace
}; 
查看1道真题和解析