Manipulate string based on format

I have two strings. One is the format, and one is the output.
For example: var string1 = "January 21 2015'; var string2 = '21 01, 15'

What I would like to do is manipulate string1 to include the date ordinals - which is fine and I can do.
Where I am struggling is how to work out where to insert the ordinal based on string2.

What would you suggest is the best way of doing this.

I already have the code to check the date number and insert the relevant ordinal but I need to work out where in the string to insert it.

The outcome should be...
21st January 2015

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Can you explain this a bit more. I understand you want to put the (st, nd, rd) into the string but not sure why this is a problem. If you are able to recognise the day surely it is a simple concatenation problem with the ordinal. If you are asking how to work out what the ordinal is you can do this
function getOrdinal(day)
  if (day == 1 || day == 21 || day == 31) return 'st';
  if (day == 2 || day == 22) return 'nd';
  if (day == 3 || day == 23) return 'rd';
  return 'th'

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.