AS3 – C# String Replace with Regular Expressions and Callback function
Uncategorized January 15th, 2009In AS3:
[AS]
…
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;
}
[/AS]
In C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ... 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; } |
No TweetBacks yet. (Be the first to Tweet this post)
Follow Me!