"入力した文章をランダムな文字数(20~100)で区切って出力するコード"を書いてもらいました.
*テキストファイルを読み込む方式.
*出力結果の表示で、1行空行入れて、区切る.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Random Text Splitter with Empty Lines</title>
</head>
<body>
<input type="file" id="fileInput"><br>
<button onclick="splitFileText()">ファイルの内容を分割</button>
<div id="result"></div>
<script>
function splitFileText() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const text = e.target.result;
let currentIndex = 0;
let result = '';
while (currentIndex < text.length) {
const randomLength = Math.floor(Math.random() * (100 - 20 + 1)) + 20;
const nextIndex = Math.min(currentIndex + randomLength, text.length);
result += text.substring(currentIndex, nextIndex) + '<br><br>';
currentIndex = nextIndex;
}
document.getElementById('result').innerHTML = result;
};
reader.readAsText(file);
}
}
</script>
</body>
</html>
これはあくまで私用の簡易ツールになります。
以下が出力結果です.
Comments