Javascript - Đổi một chuỗi thành tiêu đề chữ hoa
Viết hàm JS Đổi một chuỗi thành tiêu đề chữ hoa
Ví dụ:
Mã nguồn:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JavaScript program to convert the letters of a given string in alphabetical order.</title>
</head>
<script>
function sentenceCase (str) {
if ((str===null) || (str===''))
return false;
else
str = str.toString();
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
document.write(sentenceCase('PHP exercises. python exercises.'));
</script>
<body>
</body>
</html>
Lưu đồ thuật toán: