Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Found in old code

Found in old code

Scheduled Pinned Locked Moved The Weird and The Wonderful
19 Posts 15 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F F ES Sitecore

    Maybe the author wants the original string left unchanged? It is no longer an attribute value but now a fieldname so it makes sense to use a different variable? Have to admit, I don't really get this one :confused:

    S Offline
    S Offline
    Sanjay K Gupta
    wrote on last edited by
    #10

    Good catch. But there is nothing in code to keep string left unchanged.:) It was simple assignment. I think, first author had extract multiple values from the string but after some changes, the string was started giving single value. The second author may be don't want to change too much in code (specially substring function).:)

    ___ ___ ___
    |__ |_| |\ | | |_| \ /
    __| | | | \| |__| | | /

    1 Reply Last reply
    0
    • S Sanjay K Gupta

      var fieldName = attributeVal.substring(0, attributeVal.length - 1);

      It is javascript. :)

      ___ ___ ___
      |__ |_| |\ | | |_| \ /
      __| | | | \| |__| | | /

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #11

      That allows for an easy performance improvement with V2.0 :-D

      S 1 Reply Last reply
      0
      • S Sanjay K Gupta

        var fieldName = attributeVal.substring(0, attributeVal.length - 1);

        It is javascript. :)

        ___ ___ ___
        |__ |_| |\ | | |_| \ /
        __| | | | \| |__| | | /

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #12

        What if he didn't want the original string reference ? not a bad way to clone

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

        ----------------------------------------------- 128 bit encrypted signature, crack if you can

        J 1 Reply Last reply
        0
        • P PIEBALDconsult

          That allows for an easy performance improvement with V2.0 :-D

          S Offline
          S Offline
          Sanjay K Gupta
          wrote on last edited by
          #13

          A real example of Weird and The Wonderful. :)

          ___ ___ ___
          |__ |_| |\ | | |_| \ /
          __| | | | \| |__| | | /

          1 Reply Last reply
          0
          • S Sanjay K Gupta

            var fieldName = attributeVal.substring(0, attributeVal.length - 1);

            It is javascript. :)

            ___ ___ ___
            |__ |_| |\ | | |_| \ /
            __| | | | \| |__| | | /

            S Offline
            S Offline
            szukuro
            wrote on last edited by
            #14

            Not sure I see the issue here. This is the easiest way to remove the last character from a string.

            1 Reply Last reply
            0
            • Z ZurdoDev

              phil.o wrote:

              Why making things simple when you can over-complicate them?

              Because we are men, not women. :doh:

              There are only 10 types of people in the world, those who understand binary and those who don't.

              R Offline
              R Offline
              Rob Grainger
              wrote on last edited by
              #15

              Casual sexism alert.

              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

              1 Reply Last reply
              0
              • S Sanjay K Gupta

                var fieldName = attributeVal.substring(0, attributeVal.length - 1);

                It is javascript. :)

                ___ ___ ___
                |__ |_| |\ | | |_| \ /
                __| | | | \| |__| | | /

                R Offline
                R Offline
                Ryan Peden
                wrote on last edited by
                #16

                Well, substring omits the character at the index specified by the second parameter, so the code you listed will return attributeVal with its final character removed. Maybe that's not what this code should be doing in this case, but what you showed isn't obviously incorrect. It's exactly the code you'd want to use to remove the last character of a string, although

                attributeVal.slice(0,-1)

                would work in this case too. OTOH,

                var fieldName = attributeVal.substring(0, attributeVal.length);

                would be pointless, as it would just return attributeVal

                1 Reply Last reply
                0
                • S Sanjay K Gupta

                  var fieldName = attributeVal.substring(0, attributeVal.length - 1);

                  It is javascript. :)

                  ___ ___ ___
                  |__ |_| |\ | | |_| \ /
                  __| | | | \| |__| | | /

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #17

                  Sanjay K. Gupta wrote:

                  It is javascript. :)

                  You don't say!

                  The language is JavaScript. that of Mordor, which I will not utter here
                  This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                  "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                  1 Reply Last reply
                  0
                  • S Sanjay K Gupta

                    var fieldName = attributeVal.substring(0, attributeVal.length - 1);

                    It is javascript. :)

                    ___ ___ ___
                    |__ |_| |\ | | |_| \ /
                    __| | | | \| |__| | | /

                    J Offline
                    J Offline
                    Jeremy Falcon
                    wrote on last edited by
                    #18

                    That made my day. :laugh: :laugh:

                    Jeremy Falcon

                    1 Reply Last reply
                    0
                    • X Xmen Real

                      What if he didn't want the original string reference ? not a bad way to clone

                      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

                      ----------------------------------------------- 128 bit encrypted signature, crack if you can

                      J Offline
                      J Offline
                      Jeremy Falcon
                      wrote on last edited by
                      #19

                      That only applies to objects. For instance...

                      var a = 'howdy';
                      var b = a;
                      a = 'partner';
                      alert(b); // shows howdy

                      var x = {message: 'howdy'};
                      var y = x;
                      x.message = 'partner';
                      alert(y.message); // shows partner

                      And even if that was the coder's intent, it would still be way more readable to do something like this...

                      var a = 'blah';
                      var b = new String(a);
                      a = 'yo';
                      alert(b); // shows blah

                      Jeremy Falcon

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups