Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now