Text Case Converter | Advanced Online Text Utility Tool

TEXT CASE CONVERTER

Transform your text with various case options and use other text utilities
Character Count: 0 Word Count: 0
Additional Text Options
'); printWindow.document.close(); printWindow.focus(); printWindow.print(); } else { showNotification('Nothing to print', 'warning'); } } function convertCase(caseType) { const text = inputText.value; if (!text && caseType !== 'clear') { showNotification('Please enter some text', 'warning'); inputText.focus(); return; } hideAuxiliarySections(); let result = ''; switch (caseType) { case 'upper': result = text.toUpperCase(); break; case 'lower': result = text.toLowerCase(); break; case 'sentence': result = text.toLowerCase().replace(/(^\s*|[.!?]\s*)\S/g, match => match.toUpperCase()); break; case 'capitalize': result = text.toLowerCase().replace(/\b\w/g, match => match.toUpperCase()); break; case 'toggle': result = text.split('').map(char => char === char.toUpperCase() ? char.toLowerCase() : char.toUpperCase() ).join(''); break; case 'alternate': result = text.split('').map((char, index) => index % 2 === 0 ? char.toUpperCase() : char.toLowerCase() ).join(''); break; } outputText.value = result; if (text) showNotification('Text transformed successfully', 'success'); }function hideAuxiliarySections() { findReplaceSection.style.display = 'none'; frequencyResultsCard.style.display = 'none'; } function removeExtraSpaces() { const text = inputText.value; if (!text) { showNotification('Please enter some text', 'warning'); inputText.focus(); return; } hideAuxiliarySections(); outputText.value = text.replace(/\s+/g, ' ').trim(); showNotification('Extra spaces removed', 'success'); } function removeLineBreaks() { const text = inputText.value; if (!text) { showNotification('Please enter some text', 'warning'); inputText.focus(); return; } hideAuxiliarySections(); outputText.value = text.replace(/(\r\n|\n|\r)/gm, ' ').trim(); showNotification('Line breaks removed', 'success'); } function reverseText() { const text = inputText.value; if (!text) { showNotification('Please enter some text', 'warning'); inputText.focus(); return; } hideAuxiliarySections(); outputText.value = text.split('').reverse().join(''); showNotification('Text reversed', 'success'); }function toggleFindReplace() { hideAuxiliarySections(); findReplaceSection.style.display = findReplaceSection.style.display === 'none' ? 'block' : 'none'; if (findReplaceSection.style.display === 'block') { findTextEl.focus(); } }function executeFindReplace() { const text = inputText.value; const findVal = findTextEl.value; const replaceVal = replaceTextEl.value;if (!text) { showNotification('Please enter some text in the input field', 'warning'); inputText.focus(); return; } if (!findVal) { showNotification('Please enter text in the "Find this" field', 'warning'); findTextEl.focus(); return; } const regex = new RegExp(findVal.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'); let replacementsMade = 0; const result = text.replace(regex, (match) => { replacementsMade++; return replaceVal; });outputText.value = result; if (replacementsMade > 0) { showNotification(`${replacementsMade} replacement(s) made`, 'success'); } else { showNotification(`"${findVal}" not found`, 'info'); } }function showWordFrequency() { const text = inputText.value.trim(); if (!text) { showNotification('Please enter some text', 'warning'); inputText.focus(); return; } hideAuxiliarySections(); findReplaceSection.style.display = 'none';const words = text.toLowerCase().match(/\b\w+\b/g); if (!words) { frequencyResultsArea.textContent = 'No words found.'; frequencyResultsCard.style.display = 'block'; frequencyResultsTitle.textContent = 'Word Frequency'; showNotification('No words found', 'info'); return; }const freqMap = {}; words.forEach(word => { freqMap[word] = (freqMap[word] || 0) + 1; });const sortedFreq = Object.entries(freqMap).sort((a, b) => { if (b[1] === a[1]) { return a[0].localeCompare(b[0]); } return b[1] - a[1]; }); let output = 'Word : Count\n-------------------\n'; sortedFreq.forEach(([word, count]) => { output += `${word} : ${count}\n`; }); frequencyResultsArea.textContent = output; frequencyResultsTitle.textContent = 'Word Frequency'; frequencyResultsCard.style.display = 'block'; showNotification('Word frequency calculated', 'success'); }function showCharFrequency() { const text = inputText.value; if (!text) { showNotification('Please enter some text', 'warning'); inputText.focus(); return; }hideAuxiliarySections(); findReplaceSection.style.display = 'none';const charMap = {}; for (let char of text) { charMap[char] = (charMap[char] || 0) + 1; }const sortedCharFreq = Object.entries(charMap).sort((a, b) => { if (b[1] === a[1]) { return a[0].localeCompare(b[0]); } return b[1] - a[1]; });let output = 'Character : Count\n-----------------------\n'; sortedCharFreq.forEach(([char, count]) => { let displayChar = char; if (char === '\n') displayChar = '\\n (Newline)'; else if (char === '\t') displayChar = '\\t (Tab)'; else if (char === ' ') displayChar = "' ' (Space)";output += `${displayChar} : ${count}\n`; });frequencyResultsArea.textContent = output; frequencyResultsTitle.textContent = 'Character Frequency'; frequencyResultsCard.style.display = 'block'; showNotification('Character frequency calculated', 'success'); }function handleRemoveDuplicateLines() { const text = inputText.value; if (!text) { showNotification('Please enter some text', 'warning'); inputText.focus(); return; } hideAuxiliarySections();const lines = text.split(/\r?\n/); const uniqueLines = []; const seenLines = new Set();for (const line of lines) { if (!seenLines.has(line)) { uniqueLines.push(line); seenLines.add(line); } } outputText.value = uniqueLines.join('\n'); showNotification('Duplicate lines removed', 'success'); }function handleCountLines() { const text = inputText.value; if (!text) { outputText.value = 'Line Count: 0'; showNotification('Input is empty. Line count is 0.', 'info'); return; } hideAuxiliarySections(); const lines = text.split(/\r?\n/); let lineCount = lines.length; if (text.length === 0) { lineCount = 0; } else if (lines.length === 1 && lines[0] === '') { lineCount = 1; }outputText.value = `Total Lines: ${lineCount}`; showNotification(`Text contains ${lineCount} line(s)`, 'success'); } function showNotification(message, type = 'success') { if (toastMessageBody && notificationToastEl && bsToast) { toastMessageBody.textContent = message; notificationToastEl.classList.remove('bg-success', 'bg-danger', 'bg-warning', 'bg-info'); notificationToastEl.classList.add(`bg-${type}`); bsToast.show(); } else { console.warn("Toast notification system not fully initialized. Message:", message); } } }); Related Tools Section - Embed Friendly