Solved

perl tr/y like function

Posted on 2004-09-03
4
1,298 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
ID: 11979441
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
ID: 11980444
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
ID: 11980666
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
ID: 11980763
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now