How to loop through an array and replacing some of its values?
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
add a comment |
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
1
You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
– Jasen
Sep 23 '15 at 1:47
add a comment |
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
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
javascript for-loop replace
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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;
;
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
;
add a comment |
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;
;
add a comment |
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;
;
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;
;
answered Sep 23 '15 at 2:06
Olivier De MeulderOlivier De Meulder
2,30431927
2,30431927
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
You have your loop. Now parse, compare, and replace. What are you having trouble with exactly?
– Jasen
Sep 23 '15 at 1:47