Solved

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

Posted on 2016-11-25
4
39 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

830 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