How to convert upper to lower and replace spaces with dashes?

I want to convert good bunch of url text.

from

CUSTOMER FAQS
HOW wE can HELP
PLANNING YOUR BUDGET
CUSTOMER CASE STUDIES
TENANT DISPUTES
EXIT STRATEGIES
USEFUL dOCUMENTS
USEFUL lINKS

to

customer-faqs
how-we-can-help
planning-your-budget
customer-case-studies
tenant-disputes
exit-strategies
useful-documents
useful-links

Is there any online or offline tool which can do this?

I want to do both thing at once.


value = value.toLowerCase().replace(/ /g,'-');
  • toLowerCase -> convert this string to all lower case
  • replace(/ /g,'-') -> Globally replace (/g) all spaces (/ /) with the string -
  • See also:

  • Convert JavaScript String to be all lower case?
  • Regex for replacing a single-quote with two single-quotes

  • If you just want to have this functionality and use it locally in your browser, you can make yourself a simple html page and save it to your desktop as convert.html (or whatever). However if you're going to go that far, I'd just use a shell script/command as one of the other answers posted.

    <html>
    <body>
    
        <h2>Input</h2>
        <textarea id="input"></textarea>
        <button onClick="doConvert()">Convert</button>
    
        <hr/>
        <h2>Output</h2>
        <textarea id="output"></textarea>
    
        <script type="text/javascript">
            function doConvert() {
                var value = document.getElementById('input').value;
                var newValue = value.toLowerCase().replace(/ /g,'-');
                document.getElementById('output').value = newValue;
            }
        </script>
    
    </body>
    </html>
    

    YOURTEXT.toLowerCase().replace(/ /g,"-")
    

    tr命令可以做到这一点:

    $ tr 'A-Z ' 'a-z-'
    CUSTOMER FAQS
    customer-faqs
    HOW wE can HELP
    how-we-can-help
    
    链接地址: http://www.djcxy.com/p/21256.html

    上一篇: toLocaleLowerCase()和toLowerCase()之间的区别

    下一篇: 如何将上部转换为下部并用破折号替换空格?