in .substring(start,end) the parameters are the indexes. so in .substring(nEnd, 5) is the same as .substring(12, 5). because 12 is greater than 5, the args are switched, and become .substring(5,12). "Present 1/1(2%)".substring(5,12) returns the characters
between position 5 and 12 or "nt: 1/1"
not sure why you use such complex code when a simple regEx would work:
Member
2 Points
9 Posts
Trying to get SUBSTRING
Jan 28, 2021 03:52 PM|TarugoKing|LINK
I have a label control with text Present: 1/1(2%)
I want to change via script to Present 1(2%)
When testing, I can get the string Present: 1 but I can't get the other half (2%) . What am I missing?
document.getElementById("Label2").innerHTML = y.innerHTML.substring(0, nStart); <--- Gives me Present: 1
document.getElementById("Label2").innerHTML = y.innerHTML.substring(nEnd,5); <--- Gives me nt: 1/1
document.getElementById("Label2").innerHTML = y.innerHTML.substring(0, nStart) + y.innerHTML.substring(nEnd,5) <-- Gives me Present: 1nt: 1/1
All-Star
58144 Points
15646 Posts
Re: Trying to get SUBSTRING
Jan 28, 2021 04:42 PM|bruce (sqlwork.com)|LINK
in .substring(start,end) the parameters are the indexes. so in .substring(nEnd, 5) is the same as .substring(12, 5). because 12 is greater than 5, the args are switched, and become .substring(5,12). "Present 1/1(2%)".substring(5,12) returns the characters between position 5 and 12 or "nt: 1/1"
not sure why you use such complex code when a simple regEx would work:
Member
2 Points
9 Posts
Re: Trying to get SUBSTRING
Feb 03, 2021 08:52 PM|TarugoKing|LINK
Thank you.