/// <summary> /// Parses the specified STR. /// </summary> /// <param name="str">The STR.</param> /// <returns></returns> public static ProcessHelper Parse(string str) { // Assumes there is an .exe somwhere int exeIndex = str.IndexOf(".exe", StringComparison.CurrentCultureIgnoreCase); if (exeIndex != -1) { if (str.Length > exeIndex + 4 && str[exeIndex + 4] == '\"') { exeIndex++; } string[] pieces = StringUtilities.SplitOn(str, exeIndex + 3, true); pieces[0] = pieces[0].Trim(); pieces[1] = pieces[1].Trim(); if (pieces[0].Length > 0 && pieces[0][0] == '\"') { pieces[0] = pieces[0].Substring(1); } if (pieces[0].Length > 0 && pieces[0][pieces[0].Length - 1] == '\"') { pieces[0] = pieces[0].Substring(0, pieces[0].Length - 1); } ProcessHelper result = new ProcessHelper(); result.FileName = pieces[0]; result.Arguments = pieces[1]; return(result); } throw new NotImplementedException(); }
/// <summary> /// Replaces the specified input. /// </summary> /// <param name="input">The input.</param> /// <param name="regularExpression">The regular expression.</param> /// <param name="captureIndex">Index of the capture.</param> /// <param name="replacement">The replacement.</param> /// <returns></returns> public static string Replace(string input, string regularExpression, int captureIndex, CallbackRegexReplacement replacement) { Match m = Regex.Match(input, regularExpression); StringBuilder result = new StringBuilder(input.Length); while (m.Success) { Group g = m.Groups[captureIndex]; string[] pieces = StringUtilities.SplitOn(input, g.Index, false); result.Append(pieces[0]); result.Append(replacement(captureIndex, g.ToString())); input = pieces[1].Substring(g.Length); // Get the next match m = Regex.Match(input, regularExpression); } result.Append(input); return(result.ToString()); }