11

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.

jensgram
  • 31,109
  • 6
  • 81
  • 98
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852

3 Answers3

19
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:


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>
Community
  • 1
  • 1
T. Stone
  • 19,209
  • 15
  • 69
  • 97
  • can i give me explanation how can i use this code with any online or offline tool – Jitendra Vyas Dec 22 '09 at 07:21
  • @T.stone thx for info I've seen links but still idon;t know how to use. can u give me any link step by step link. I don't know javascript hardcore programming and regex – Jitendra Vyas Dec 22 '09 at 07:31
  • This is getting close to me doing everything so I'm going to stop. The functionality you're asking about is commonly referred to as right trimming. Try googling it (http://www.google.com/search?rlz=1C1GGLS_enUS348US349&sourceid=chrome&ie=UTF-8&q=right+trim+javascript) – T. Stone Dec 22 '09 at 08:50
6
YOURTEXT.toLowerCase().replace(/ /g,"-")
YOU
  • 120,166
  • 34
  • 186
  • 219
2

The tr command can do this:

$ tr 'A-Z ' 'a-z-'
CUSTOMER FAQS
customer-faqs
HOW wE can HELP
how-we-can-help
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285