Solved

How to standardize Token in a string by making upper case and removing all spaces?

Posted on 2016-11-25
4
35 Views
Last Modified: 2016-11-25
If I have a token in a string but I want to ensure it is only upper case and contains no spaces, how would I do this? Only the token will have the square brackets in the string.

Input Examples:

1) ?n1=v1&n2= [new vs returning]&n3=v3
2) [New vs Returning]&n3=v3
3 [  NEW     VS retur  nin g      ]&n3=v3
4) ?n1=v1&n2= [current url]&n3=v3
5) ?n1=v1&n2= [    CurRent   uR  l  ]&n3=v3

Output Examples:

1) ?n1=v1&n2=[NEWVSRETURNING]&n3=v3
2) ?n1=v1&n2=[NEWVSRETURNING]&n3=v3
3) ?n1=v1&n2=[NEWVSRETURNING]&n3=v3
4) ?n1=v1&n2=[CURRENTURL]&n3=v3
5) ?n1=v1&n2=[CURRENTURL]&n3=v3

Thanks!
0
Comment
Question by:894359
  • 3
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41902073
var standardizeToken = function(search) {
     return search.replace(/\[([^\]]*)\]/, function(found) {
            return found.replace(/\s/g,"").toUpperCase();
     });
}

Open in new window

0
 

Author Comment

by:894359
ID: 41902075
Hi Leakim,
This doesn't seem to be working for me?
0
 

Author Comment

by:894359
ID: 41902076
Sorry my mistake! Thanks!
0
 

Author Closing Comment

by:894359
ID: 41902077
Thanks again!
1

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question