AS3 – C# String Replace with Regular Expressions and Callback function
.NET, Flash, Flex January 15th, 2009In AS3:
Actionscript:
-
...
-
var regExpDigitString:String = "\\d+";
-
modified = original.replace(new RegExp(regExpDigitString, "gi"), findSuffix);
-
...
-
-
private function findSuffix():String {
-
var result:String = arguments[0];
-
var index:int = arguments[1];
-
var input:String = arguments[2];
-
-
...
-
-
return result;
-
}
In C#
C#:
-
...
-
String regExpDigitString = "\\d+";
-
modified = Regex.Replace(original, regExpDigitString, new MatchEvaluator(findSuffix), RegexOptions.IgnoreCase);
-
...
-
-
private String findSuffix(Match m) {
-
String result = m.ToString();
-
int index = m.Index;
-
String input = original; //apparently you can't get the original string out of the Mach Object, so you'll need a reference to the original Object in your class.
-
-
...
-
-
return result;
-
}
Recent Comments