Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding 'substitute' method for variable injections #164

Open
wants to merge 1 commit into from

1 participant

@mboudreau

Adding own 'substitute' method (for variable injections) to replace the one in mx.utils.StringUtil.

@sangupta sangupta referenced this pull request from a commit in sangupta/as3corelib
@sangupta sangupta Added substitute method - fix for issue #164 on original fork d617d1e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 12, 2011
  1. @mboudreau

    Adding own 'substitute' method (for variable injections) to replace t…

    mboudreau authored
    …he one in mx.utils.StringUtil.
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 1 deletion.
  1. +28 −1 src/com/adobe/utils/StringUtil.as
View
29 src/com/adobe/utils/StringUtil.as
@@ -42,7 +42,34 @@ package com.adobe.utils
*/
public class StringUtil
{
-
+ /**
+ * Variable string injection. Replaces all instances of '{n}' with
+ * the parameter equivalent where 'n' equals a number.
+ *
+ * @param string The first string to injects variables into.
+ *
+ * @param ... The unlimited number of variables to be injected.
+ *
+ * @returns A string with the variables injected
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function substitute(string:String, ...params:Array):String
+ {
+ // Check to see if there's something to inject
+ if(params && params.length > 0)
+ {
+ // Iterate through array, try to inject vars in string
+ for(var i:uint = 0, len:uint = params.length; i<len; i++)
+ {
+ string = StringUtil.replace(string, '{' + i + '}', params[i].toString());
+ }
+ }
+
+ return string;
+ }
/**
* Does a case insensitive compare or two strings and returns true if
Something went wrong with that request. Please try again.