Skip to content

Commit 2f1c05b

Browse files
committed
Bugfixed strtr
1 parent a58dba8 commit 2f1c05b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

functions/strings/strtr.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
function strtr (str, from, to) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Brett Zamir
4+
// + input by: uestla
5+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
46
// * example 1: $trans = {"hello" : "hi", "hi" : "hello"};
57
// * example 1: strtr("hi all, I said hello", $trans)
68
// * returns 1: 'hello all, I said hi'
79
// * example 2: strtr('äaabaåccasdeöoo', 'äåö','aao');
810
// * returns 2: 'aaabaaccasdeooo'
11+
// * example 3: strtr('ääääääää', 'ä','a');
12+
// * returns 3: 'aaaaaaaa'
913

1014
var fr = '', i = 0, lgth = 0;
1115

@@ -21,7 +25,7 @@ function strtr (str, from, to) {
2125
lgth = from.length;
2226
}
2327
for (i = 0; i < lgth; i++) {
24-
str = str.replace(from[i], to[i]);
28+
str = str.replace(from[i], to[i], 'g');
2529
}
2630

2731
return str;

0 commit comments

Comments
 (0)