views:

59

answers:

1

How do you replace text based on a charcode?

+1  A: 
var charcode = 34; //example, put whatever here
var char = String.fromCharCode(charcode);

var string_to_edit = 'This is my string.';

var new string = string_to_edit.replace(char, 'whatever you are replacing with');

You may have to make that a pattern to use replace(), but I don't think so.

UltimateBrent
@UltimateBrent. Note that strings are inmutable in Actionscript. So you can't really change a string. In this case, it means you have to re-assign the string returned by `replace` to `string_to_edit` (or any other variable, if needed).
Juan Pablo Califano
my bad, fixed. was writing from the hip, hadn't checked it.
UltimateBrent
This is OK, as far as it goes, but it's not AS3. You're not casting and/or scoping variables, etc.
Robusto