1 Reply Latest reply on Sep 26, 2006 11:12 AM by TimSymons

    Help required in changing the contents of a string

      hi guys

      I'm reading in a series of xml files which contain a passage of text like that below
      Here is an example:

      Since iritis is associated with HLA B27, it may obviously occur in any of the <GLOSS ID="seronegative">seronegative</GLOSS><SMALLIMAGE width="348" height="254">charcothip.jpg</SMALLIMAGE>

      I am displaying this text in a html textfield. However for it to display properly, I need to replace the <SMALLIMAGE> tag with
      <IMG SRC="charcothip.jpg"/> etc
      I can do a replace on <SMALLIMAGE and turn it to <IMG , however how do i add the SRC="charcothip.jpg"> ?

      can anybody provide me with some suggestions for how to do this?
      Any ideas and suggestions would really be appreciated

        • 1. Re: Help required in changing the contents of a string
          TimSymons Level 1
          If you can replace <SMALLIMAGE with <IMG then I am not sure why you couldn't include the SRC="charcothip.jpg" with the <IMG portion?

          How are you replacing it currently? Could you store the replacement string in a variable and use it instead.

          var replacementString:String = "<IMG SRC=\"charcothip.jpg\"";

          Then you could do something like this (assume the myStr holds the XML String):

          var myArr:Array = new Array();
          myArr = myStr.split("<SMALLIMAGE");
          myStr = myArr.join(replacementString);

          Obviously, this will only work if you are replacing all of the <SMALLIMAGE pieces with the same image. If not then you could use the following:

          var searchFor:String = "<SMALLIMAGE";
          var newString:String = myStr.substring(0, myStr.indexOf(searchFor));
          newString += replacementString;
          newString += myStr.substr(myStr.indexOf(searchFor)+searchFor.length);

          You can keep the width and height attributes since Flash will recognize those when rendering the HTML.