Results 1 to 4 of 4

Thread: Does this computer see mpos2? if not, why?

  1. #1
    Join Date
    Oct 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Does this computer see mpos2? if not, why?

    var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]");
    var mpos1 = input.indexOf("[[Image");

    for(i=mpos1;i<=input.length;i++)
    {
    var mpos2 = input.indexOf(":");
    }

    var istr1 = input.substring(mpos1, mpos2);

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hm. I'd do:
    Code:
    var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]"),
      text = input.match(/[[Image:([^\|]+)|([^\]]+)]]/),
      url = text[0];
    text = text[1];
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    	    <script type= "text/javascript">
    	   var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]");
    		var mpos1 = input.indexOf("[[Image:");
    		var init = "[[Image:"
    		var colon = init.lastIndexOf(":")
    		
    	for(i=mpos1;i<=input.length;i++)
    	   {
    	   var mpos2 = input.indexOf("|");
    	   }
            for(i=mpos1;i<=input.length;i++)
    	   {
    	   var mpos3 = input.indexOf("]]");
    	   }
    		var istr0 = input.substring(0, mpos1)
    		var istr1 = input.substring(mpos1, colon);
    		var websi = input.substring(colon, mpos2)
    		var istr2 = input.substring(mpos2, mpos2+1);
    		var istr3 = input.substring(mpos2+1, mpos3);
    		var istr4 = input.substring(mpos3, mpos3+2);
    		var istr5 = input.substring(mpos3+2, input.length);
    
    	    if(istr1.indexOf("[[Image:") != -1)
    		  {
    		   var ipos1 = istr1.replace("[[Image:", '<img src="http://en.wikipedia.org/wiki/Image:');
    		  }
    	    
    	    if(istr2.indexOf("|") != -1)
    		  {
    		   var ipos2 = istr2.replace("|", '" alt="');
    		  }
    	    if(istr4.indexOf("]]") != -1)
    		  {
    		   var ipos3 = istr4.replace("]]", '</img>"');
    		  }
    	     var newimage = (istr0+ipos1+websi+ipos2+istr3+ipos3+istr5);
    		document.write(newimage);	
    ----
    
    when I output this, it doesn't output ipos1.
    It doesn't even transform it.
    
    I'm thinkin it has to do with the fact that i can't find mpos2.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is really very ugly. Regex is much nicer.
    Code:
    function unWikifyImages(str) {
      return str.replace(/\[\[Image:([^\|]+)\|([^\|]+)\]\]/, '<img src="$1" alt="$2">');
    }
    Last edited by Twey; 10-08-2006 at 11:56 AM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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