/    Sign up×
Community /Pin to ProfileBookmark

Manipulating strings. Please help

I have been asked to extract the number portion from the span below. I assume I need to be using the slice() function but what I can not figure out is how to grab only the number portion. The tricky thing is, this number portion is going to change everytime the page is loaded.

I am thinking I am going to have to create a function using getElementbyId(‘sliceMe’).innerHTML that creates a character array. Then somehow tell it to start slicing once it runs into a Number.

Is this even possible? Thanks for help!!

[I]<span id=”sliceMe”>Here is the number I need to return<br />
<br />
<br />
90909090
</span>[/I]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameMar 03.2009 — [CODE]<html>
<head>

<script type="text/javascript">
window.onload = function () {
var elemStr = document.getElementById('sliceMe').innerHTML;
var elemStrNumbers = elemStr.match(/d+/g); //matches all simultaneous digits
alert("This is array of all numbers from string:n" + elemStrNumbers);
alert("This is a particular number from the array of numbersn" + elemStrNumbers[2]);
}
</script>
</head>
<body>
<span id="sliceMe">Here is the number I need to return<br />
<br />
<br />
90909090 note we can 123pull 99 or all or 1 numbers from string
</span>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@kpikulauthorMar 03.2009 — Damn bro, what I had going on in my head what a lot move involved than this.

Thanks for simplifying things for me!
×

Success!

Help @kpikul spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...