Solved

perl tr/y like function

Posted on 2004-09-03
4
1,297 Views
Last Modified: 2009-12-16
is there a tr/// like function. example being translating upper to lower case (and not using toLowerCase) - tr/A-Z/a-z/ or something like tr/0-9/a-j/.

i'm tired - tia.
0
Comment
Question by:ren_b
  • 2
4 Comments
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 100 total points
Comment Utility
Not to my knowledge. You might be able to fudge MOST of them with stringVar.replace(regex,replacement), however.

Also, because tr/// returns the number of matches (if my memory serves me correctly), you'd have to use a separate match like this:

var totalMatches=stringVar.split(regex).length;

0
 
LVL 6

Author Comment

by:ren_b
Comment Utility
i'm just looking for a yes or no answer, and if yes, what's the function name. creating it wouldn't be a problem, iff i have to.
0
 
LVL 7

Accepted Solution

by:
Xxavier earned 400 total points
Comment Utility
There is no such nethod in the stand JS functions see http://www.devguru.com/Technologies/ecmascript/quickref/js_functions.html  the facility is privided as the to LowerCase method of the string object. It can be wrpped in a function as so though.

<script>
 function tr(str){
  return str.toLowerCase()
 }
 str="abcDEFGHijk"
 alert(str+' '+tr(str))
</script>


0
 
LVL 6

Author Comment

by:ren_b
Comment Utility
i wasn't looking for a toLowerCase function - a javascript version of the tr program or tr function in perl - which you say there is no method. that's all i needed to know.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now