Iaik.Utils.SimpleFormatter.Format C# (CSharp) Method

Format() public method

Formats a string, see class description for formatting instructions
public Format ( string format ) : string
format string
return string
        public string Format(string format, params object[] args)
        {
            StringBuilder formatted = new StringBuilder ();
            int? offset = 0;

            while (offset != null) {
                int lastOffset = offset.Value;
                offset = FindStartMarker (offset.Value, format);

                try {
                    if (offset != null) {
                        formatted.Append (format.Substring (lastOffset, offset.Value - lastOffset));
                        offset++;
                        string currentFormatPacket = GetFormatPacket (ref offset, format);
                        formatted.Append (FormatPacket (currentFormatPacket, args));
                    } else {
                        formatted.Append (format.Substring (lastOffset));
                    }
                } catch (Exception) {
                    if (_throwException)
                        throw;
                }

            }

            return formatted.ToString ();
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Looks for {[..]} constructions in the specified expression,
        /// and calls the callback for each of them replacing its occurance with the
        /// return value of the callback
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="cb"></param>
        /// <returns></returns>
        public static string ReplaceVariables(string expression, VariableDetectedCB cb)
        {
            SimpleFormatter f = new SimpleFormatter ();
            f.OnGetParameter += delegate(string parameterName) {
                return cb (parameterName);
            };

            return f.Format (expression);
        }
All Usage Examples Of Iaik.Utils.SimpleFormatter::Format