Replace the X's in the format string with successive placeholders, and split the input string value into a string array, then apply string.Format():
public static string FormatSplitAndJoin(string input, string formatTemplate, string delimiter = "_", string placeholder = "X")
{
// split "a_b_c" into ["a", "b", "c"]
var parts = input.Split(delimiter);
// turn "X_X_X" into "{0}_{1}_{2}"
var index = 0;
var formatString = Regex.Replace(formatTemplate, placeholder, m => string.Format("{{{0}}}", index++));
// validate input length
if(index > parts.Length)
throw new ArgumentException(string.Format("input string resulted in fewer arguments than expected, {0} placeholders found", index));
// apply string.Format()
return string.Format(formatString, parts);
}
Now you can do:
var str = "SOME_ORIGINAL_FIELD_NAME";
var format1 = "XX_X_X";
var format2 = "X_XXX";
var strFormat1 = FormatSplitAndJoin(str, format1); // SOMEORIGINAL_FIELD_NAME
var strFormat2 = FormatSplitAndJoin(str, format2); // SOME_ORIGINALFIELDNAME