How to loop through an array and replacing some of its values?










-3














I have now the following code:



shp = this.getField("shp");
out = this.getField("txt")
p = shp.value.split("");
pn = "";

for (i = 0; i < p.length; i++)
pn += p[i].charCodeAt(0);
;


Now I want to loop through pn and check for values greater than 56,



these values I want to replace with (the value - 63)%10



how can I do that?



So, to be a little bit clearer:



I want to rewrite the following vba code to run it on adobe acrobat:



Function upsp(number)
qsm = 0
For i = 1 To 15
p = Mid(number, i, 1)
If Asc(p) > 57 Then p = (Asc(p) - 63) Mod 10
qsm = qsm + (p * (2 - i Mod 2))
Next
upsp = 10 - (qsm Mod 10)
If upsp = 10 Then upsp = 0
End Function


this code calculate a checksum for a ups tracking number.










share|improve this question



















  • 1




    You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
    – Jasen
    Sep 23 '15 at 1:47















-3














I have now the following code:



shp = this.getField("shp");
out = this.getField("txt")
p = shp.value.split("");
pn = "";

for (i = 0; i < p.length; i++)
pn += p[i].charCodeAt(0);
;


Now I want to loop through pn and check for values greater than 56,



these values I want to replace with (the value - 63)%10



how can I do that?



So, to be a little bit clearer:



I want to rewrite the following vba code to run it on adobe acrobat:



Function upsp(number)
qsm = 0
For i = 1 To 15
p = Mid(number, i, 1)
If Asc(p) > 57 Then p = (Asc(p) - 63) Mod 10
qsm = qsm + (p * (2 - i Mod 2))
Next
upsp = 10 - (qsm Mod 10)
If upsp = 10 Then upsp = 0
End Function


this code calculate a checksum for a ups tracking number.










share|improve this question



















  • 1




    You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
    – Jasen
    Sep 23 '15 at 1:47













-3












-3








-3







I have now the following code:



shp = this.getField("shp");
out = this.getField("txt")
p = shp.value.split("");
pn = "";

for (i = 0; i < p.length; i++)
pn += p[i].charCodeAt(0);
;


Now I want to loop through pn and check for values greater than 56,



these values I want to replace with (the value - 63)%10



how can I do that?



So, to be a little bit clearer:



I want to rewrite the following vba code to run it on adobe acrobat:



Function upsp(number)
qsm = 0
For i = 1 To 15
p = Mid(number, i, 1)
If Asc(p) > 57 Then p = (Asc(p) - 63) Mod 10
qsm = qsm + (p * (2 - i Mod 2))
Next
upsp = 10 - (qsm Mod 10)
If upsp = 10 Then upsp = 0
End Function


this code calculate a checksum for a ups tracking number.










share|improve this question















I have now the following code:



shp = this.getField("shp");
out = this.getField("txt")
p = shp.value.split("");
pn = "";

for (i = 0; i < p.length; i++)
pn += p[i].charCodeAt(0);
;


Now I want to loop through pn and check for values greater than 56,



these values I want to replace with (the value - 63)%10



how can I do that?



So, to be a little bit clearer:



I want to rewrite the following vba code to run it on adobe acrobat:



Function upsp(number)
qsm = 0
For i = 1 To 15
p = Mid(number, i, 1)
If Asc(p) > 57 Then p = (Asc(p) - 63) Mod 10
qsm = qsm + (p * (2 - i Mod 2))
Next
upsp = 10 - (qsm Mod 10)
If upsp = 10 Then upsp = 0
End Function


this code calculate a checksum for a ups tracking number.







javascript for-loop replace






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 4:50









Cœur

17.5k9103145




17.5k9103145










asked Sep 23 '15 at 1:36









renokl2014renokl2014

618




618







  • 1




    You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
    – Jasen
    Sep 23 '15 at 1:47












  • 1




    You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
    – Jasen
    Sep 23 '15 at 1:47







1




1




You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
– Jasen
Sep 23 '15 at 1:47




You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
– Jasen
Sep 23 '15 at 1:47












2 Answers
2






active

oldest

votes


















0














Try this:



shp = this.getField("shp");
out = this.getField("txt")
p = shp.value.split("");
pn = "";

for (i = 0; i < p.length; i++)
// pn += p[i].charCodeAt(0);
if (p[i]>56) p[i] = (p[i] - 63)%10;
;





share|improve this answer




























    0














    Why not your code but with



    for (i = 0; i < p.length; i++) 
    if(p[i].charCodeAt(0) > 56) pn += (p[i].charCodeAt(0) -63)%10;//do you want 10 percent or modulus of 10? %10 will be the modulus /10 woul be 10 percent
    else
    pn += p[i].charCodeAt(0);
    ;


    If it's not what you're looking for you should rephrase the question, because I honestly didn't get it.






    share|improve this answer




















    • ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
      – Caio Wilson
      Sep 23 '15 at 2:27










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32729657%2fhow-to-loop-through-an-array-and-replacing-some-of-its-values%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try this:



    shp = this.getField("shp");
    out = this.getField("txt")
    p = shp.value.split("");
    pn = "";

    for (i = 0; i < p.length; i++)
    // pn += p[i].charCodeAt(0);
    if (p[i]>56) p[i] = (p[i] - 63)%10;
    ;





    share|improve this answer

























      0














      Try this:



      shp = this.getField("shp");
      out = this.getField("txt")
      p = shp.value.split("");
      pn = "";

      for (i = 0; i < p.length; i++)
      // pn += p[i].charCodeAt(0);
      if (p[i]>56) p[i] = (p[i] - 63)%10;
      ;





      share|improve this answer























        0












        0








        0






        Try this:



        shp = this.getField("shp");
        out = this.getField("txt")
        p = shp.value.split("");
        pn = "";

        for (i = 0; i < p.length; i++)
        // pn += p[i].charCodeAt(0);
        if (p[i]>56) p[i] = (p[i] - 63)%10;
        ;





        share|improve this answer












        Try this:



        shp = this.getField("shp");
        out = this.getField("txt")
        p = shp.value.split("");
        pn = "";

        for (i = 0; i < p.length; i++)
        // pn += p[i].charCodeAt(0);
        if (p[i]>56) p[i] = (p[i] - 63)%10;
        ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 23 '15 at 2:06









        Olivier De MeulderOlivier De Meulder

        2,30431927




        2,30431927























            0














            Why not your code but with



            for (i = 0; i < p.length; i++) 
            if(p[i].charCodeAt(0) > 56) pn += (p[i].charCodeAt(0) -63)%10;//do you want 10 percent or modulus of 10? %10 will be the modulus /10 woul be 10 percent
            else
            pn += p[i].charCodeAt(0);
            ;


            If it's not what you're looking for you should rephrase the question, because I honestly didn't get it.






            share|improve this answer




















            • ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
              – Caio Wilson
              Sep 23 '15 at 2:27















            0














            Why not your code but with



            for (i = 0; i < p.length; i++) 
            if(p[i].charCodeAt(0) > 56) pn += (p[i].charCodeAt(0) -63)%10;//do you want 10 percent or modulus of 10? %10 will be the modulus /10 woul be 10 percent
            else
            pn += p[i].charCodeAt(0);
            ;


            If it's not what you're looking for you should rephrase the question, because I honestly didn't get it.






            share|improve this answer




















            • ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
              – Caio Wilson
              Sep 23 '15 at 2:27













            0












            0








            0






            Why not your code but with



            for (i = 0; i < p.length; i++) 
            if(p[i].charCodeAt(0) > 56) pn += (p[i].charCodeAt(0) -63)%10;//do you want 10 percent or modulus of 10? %10 will be the modulus /10 woul be 10 percent
            else
            pn += p[i].charCodeAt(0);
            ;


            If it's not what you're looking for you should rephrase the question, because I honestly didn't get it.






            share|improve this answer












            Why not your code but with



            for (i = 0; i < p.length; i++) 
            if(p[i].charCodeAt(0) > 56) pn += (p[i].charCodeAt(0) -63)%10;//do you want 10 percent or modulus of 10? %10 will be the modulus /10 woul be 10 percent
            else
            pn += p[i].charCodeAt(0);
            ;


            If it's not what you're looking for you should rephrase the question, because I honestly didn't get it.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 23 '15 at 2:25









            Caio WilsonCaio Wilson

            154110




            154110











            • ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
              – Caio Wilson
              Sep 23 '15 at 2:27
















            • ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
              – Caio Wilson
              Sep 23 '15 at 2:27















            ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
            – Caio Wilson
            Sep 23 '15 at 2:27




            ps.: why are you using charcodeat()? Stating what you're trying to accomplish might help us answering. :)
            – Caio Wilson
            Sep 23 '15 at 2:27

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32729657%2fhow-to-loop-through-an-array-and-replacing-some-of-its-values%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Darth Vader #20

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Ondo