dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] Split/Join causing hairloss

  1. #1
    Member
    Join Date
    Mar 2007
    Posts
    79

    resolved [RESOLVED] Split/Join causing hairloss

    Hey,

    Can anyone help? Have done some searching and I know I should be using some sort of substring function but I've had 2.5 hours sleep and am not thinking straight!

    I have a string that I need to extract part of between 2 references.
    An example would be...
    "This is a string. Here is a link <gurl>http://www.example.com</gurl>"

    I want to be able to extract the link between the tags and then create a new href string ie. <a href="http://www.example.com">http://www.example.com</a> and put it back.

    Also want to do a similar thing but using img tag. So in my string I will have <image>http://www.flick.com/photo.jpg</image> and convert it to <img src=".....">


    Any help would be greatful

    Regards

    James

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,131
    Spider through your string using .indexOf(">",lastidx+1)...something like this...

    Code:
    var done:Boolean = false;
    var last:int = 0;
    var textStrings:Array = [];
    while (!done) {
    var starttag:int = str.indexOf("<",last);
    if (starttag<0) {
    done = true;
    break;
    }
    var tag:String = str.substr(openat,str.indexOf(" ",starttag)-starttag);
    var endtag:int = str.indexOf(">",starttag);
    var textStrings.push(str.substr(endtag,str.indexOf("<",endtag)-endtag));
    last = str.indexOf(">",endtag);
    }
    These could be off by a character here or there, I'm tired...

  3. #3
    Member
    Join Date
    Mar 2007
    Posts
    79
    Ok, gave up on that idea and took another route.
    I was adding links to google calendar events but it removes the html so I just add an | symbol in the tags and google doesn't remove it, then i just remove it in flash with
    PHP Code:
    gDetails gDetails.split("|").join(""); 
    so the htmlText box can read it properly

  4. #4
    WohOoooooo zompo's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    138
    A note to someone who finds this in a search is that you can use regular expressions in actionscript 3, instead of using all the indexOf's in joshstrike example.


    Try out my game http://alpha.bombwar.com - Alphakey: fkaplha

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center