Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    replace loop case quandry

    I have a unicode character replacement routine (not my own) which works fine - except it ignores uppercase. In the code below the 'N' and 'A' just do not register.
    Code:
    var paliWord = $(this).find('.nameP').text(); // replace unicode with regular letters
    	String.prototype.htmlProtect = function() { var replace_map;
    				replace_map = {	'\u0101': 'a',
    							'\u012B': 'i',
    							'\u016B': 'u',
    							'\u00F1': 'n',
    							'\u00D1': 'N',
    							'\u0100': 'A' };
    	return this.replace(/[\u0101\u012B\u016B\u00F1\u00D1\u0100]/gi, function(match) {
        return replace_map[match]; }); };
    		var paliWord = paliWord.htmlProtect();
    I have tried changing the order, using entities, digital, decimal, a sprinkle of dried lizards gonads.. - etc.

    I am open to both a fix here or an alternative routine.
    thx

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,275
    Thanks
    10
    Thanked 581 Times in 562 Posts
    this is just a guess, but will changing
    Code:
    return this.replace(/[\u0101\u012B\u016B\u00F1\u00D1\u0100]/gi, function(match) {
    to
    Code:
    return this.replace(/([\u0101\u012B\u016B\u00F1\u00D1\u0100])/gi, function(whole, match) {
    work?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    @arfa, I tested your code and it works.

    PHP Code:
    "īūñÑĀ".htmlProtect(); //returns "iunNA" 

  • #4
    New Coder
    Join Date
    Sep 2006
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    tangled

    @glenngv
    Indeed, tis true.

    I took time to test in an isolated situation and see, yes, it does work. I should have done this in the first place

    What I now need to do is see where I am going wrong feeding the loop.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by arfa View Post
    @glenngv
    Indeed, tis true.

    I took time to test in an isolated situation and see, yes, it does work. I should have done this in the first place

    What I now need to do is see where I am going wrong feeding the loop.
    Try it in different browsers, and maybe with different settings.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Debug if this line returns the expected value.

    Code:
    var paliWord = $(this).find('.nameP').text();

  • #7
    New Coder
    Join Date
    Sep 2006
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    nailed it :)

    I appreciate your kind suggestions. Thank you.

    It was basically a problem that I increasingly find I have to watch for, deal with, or some such. Dynamic builds... with stuff coming from a variety of sources and being fed in a variety of ways to a variety of displays depending on a variety of user choices. Well, I try to keep track.

    One option l.c. first, another (should be) u.c. first.
    Sorted


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •