PDA

View Full Version : replacing a substing in an xml file



jonhallewell
October 18th, 2008, 05:44 PM
I am importing an xml file, and populating a dynamic text box with some html text. However the character for a british pound sign £ is rendered £ in part of the html.

Is there a way I can find and replace all instances of £ with £ after I have imported the xml?

theCodeBot
October 18th, 2008, 05:50 PM
I am importing an xml file, and populating a dynamic text box with some html text. However the character for a british pound sign £ is rendered £ in part of the html.

Is there a way I can find and replace all instances of £ with £ after I have imported the xml?
str.replace("£","£");

I think that's the correct syntax... not sure... I might be thinking Javascript.

jonhallewell
October 20th, 2008, 02:48 PM
this isn't working. I'm having problems getting the £ converted into anything, let alone anything that will display the £ character. Anyone got any ideas.


str.replace("£","£");

I think that's the correct syntax... not sure... I might be thinking Javascript.

theCodeBot
October 20th, 2008, 04:06 PM
//Say the string to play with is str1
public var str:String = "blah blah costs £3,00";
//Sorry if I made that look wrong, I'm an American who speaks a little French...
String.prototype.strReplace = function(toFind:String,toInsert:String) {
var lastInd:int = 0;
while (this.indexOf(toFind)!==-1) {
lastInd = this.indexOf(toFind);
this = this.substr(lastInd,this.indexOf(toFind))+toInsert +this.substr(this.indexOf(toFind)+toFind.length);
}
}
str.strReplace("£","£");
trace(str);



...I think that's close. Obviously I'm not definitely right :P