www.webdeveloper.com
Results 1 to 6 of 6

Thread: using metacharacter in if statment

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    10

    Question using metacharacter in if statment

    how to write this in javascript:

    if (file == any element end with .HTML) {

    do somthing

    }



    thanks

  2. #2
    Join Date
    Oct 2012
    Posts
    10

    Question

    hi

    Code:
    <script type=text/javascript>
    
    var dd = ["a.mp3","b.wav","c.flv","d.wma",.....];
    
    for (i=0;i<4;i++) {
    if (dd[i] == *.wma) {
    
    document.write(" WMA ");
    }
    }
    </script>
    *.wma
    or
    $wma >>>> any element end with wma

    its possible to do this in javascript?

  3. #3
    Join Date
    Mar 2009
    Posts
    452
    <script type=text/javascript>

    var dd = ["a.mp3","b.wav","c.flv","d.wma"];

    for (i=0;i<4;i++) {
    var ext=dd[i].substring(dd[i].lastIndexOf('.')+1,dd[i].length);
    if (ext == 'wma') {
    document.write(" WMA ");
    }
    }
    </script>

  4. #4
    Join Date
    Oct 2012
    Posts
    10

    resolved

    Quote Originally Posted by ZABI View Post
    <script type=text/javascript>

    var dd = ["a.mp3","b.wav","c.flv","d.wma"];

    for (i=0;i<4;i++) {
    var ext=dd[i].substring(dd[i].lastIndexOf('.')+1,dd[i].length);
    if (ext == 'wma') {
    document.write(" WMA ");
    }
    }
    </script>
    its working

    thanks alot

  5. #5
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Or with a regular expression

    Code:
    if (/\.HTML$/.test(file)) {
       // do something if file end by .HTML
    }
    Slashes are the regular expression delimiters. The point must be escaped and the dollar match at the end of the string.

  6. #6
    Join Date
    Oct 2012
    Posts
    10

    resolved

    Quote Originally Posted by 007Julien View Post
    Or with a regular expression

    Code:
    if (/\.HTML$/.test(file)) {
       // do something if file end by .HTML
    }
    Slashes are the regular expression delimiters. The point must be escaped and the dollar match at the end of the string.
    Code:
    <script type=text/javascript>
    
    var dd = ["a.mp3","b.wav","f.html","d.wma","c.flv"];
    
    for (i=0;i<5;i++) {
    
         if (/\.html$/.test(dd[i])) {
             document.write(" HTML ");    // <iframe ....>
    }
    }
    
    </script>
    another method

    its working too


    I have learned new things that I never knew before


    thanks a lot i appreciate it

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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