开发者

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

开发者 https://www.devze.com 2022-12-15 01:53 出处:网络
I w开发者_JAVA技巧ant to convert good bunch of url text. from CUSTOMER FAQS HOW wE can HELP PLANNING YOUR BUDGET

I w开发者_JAVA技巧ant 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,"-")


The tr command can do this:

$ tr 'A-Z ' 'a-z-'
CUSTOMER FAQS
customer-faqs
HOW wE can HELP
how-we-can-help
0

精彩评论

暂无评论...
验证码 换一张
取 消