www.webdeveloper.com
Results 1 to 3 of 3

Thread: Get dimensions from text

  1. #1
    Join Date
    Mar 2006
    Posts
    58

    Get dimensions from text

    I have a string that looks similar to this:
    Code:
    tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500705)
    I want to strip the text until I get the value 500 & 705. I want them as two separate values. How can I do this in javascript?

  2. #2
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    373
    Something like this should work:
    Code:
    result = "tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500705)".match(/.*\((\d*)(\d*)\)/
    if (result != null) {
      var picHeight=Number(result[1]);
      var picWidth=Number(result[2]);  }
    You will probably want to refer to a variable or fieldname.value instead of a literal though. If you just want to store or display that without using it in a calculation, you won't need the Number() function. BTW, result is not a reserved word, just the name of an array that will be created if it doesn't exist already.

  3. #3
    Join Date
    Mar 2006
    Posts
    58
    Quote Originally Posted by wbport View Post
    Something like this should work:
    Code:
    result = "tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500705)".match(/.*\((\d*)(\d*)\)/
    if (result != null) {
      var picHeight=Number(result[1]);
      var picWidth=Number(result[2]);  }
    You will probably want to refer to a variable or fieldname.value instead of a literal though. If you just want to store or display that without using it in a calculation, you won't need the Number() function. BTW, result is not a reserved word, just the name of an array that will be created if it doesn't exist already.
    I tried your code but it doesn't seem to work. You can see online version here http://jsfiddle.net/97hHA/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles