@@ -747,10 +747,10 @@ public static string ReplaceDefaults(this string inputValue, string old1, string
747
747
/// <summary>
748
748
/// Replace placeholder in a template with value of property
749
749
/// </summary>
750
- /// <param name="template">The template, e.G. ID:{ID}</param>
750
+ /// <param name="template">The template with placeholder in {} , e.G. ID:{ID} </param>
751
751
/// <param name="obj">The object that is used to look at the properties</param>
752
752
/// <returns>Any found property placeholder is replaced by the property value</returns>
753
- public static string ReplacePlaceholder ( this string template , object obj )
753
+ public static string ReplacePlaceholderWithPropertyValues ( this string template , object obj )
754
754
{
755
755
if ( template . IndexOf ( '{' ) == - 1 )
756
756
return template ;
@@ -775,7 +775,40 @@ public static string ReplacePlaceholder(this string template, object obj)
775
775
foreach ( var pro in placeholder )
776
776
template = template . ReplaceCaseInsensitive ( pro . Key , pro . Value ) ;
777
777
778
- return template ;
778
+ return template . Replace ( " " , " " ) ;
779
+ }
780
+
781
+ /// <summary>
782
+ /// Replace placeholder in a template with the text provide in the parameters the order of the placeholders is important not their contend
783
+ /// </summary>
784
+ /// <param name="template">The template with placeholder in {}, e.G. ID:{ID} </param>
785
+ /// <param name="values">a variable number of text that will replace the placeholder in order of appearance</param>
786
+ /// <returns>Any found property placeholder is replaced by the provide text</returns>
787
+ public static string ReplacePlaceholderWithText ( this string template , params string [ ] values )
788
+ {
789
+ if ( template . IndexOf ( '{' ) == - 1 )
790
+ return template ;
791
+
792
+ // get all placeholders in {}
793
+ var rgx = new Regex ( @"\{[^\}]+\}" ) ;
794
+
795
+ var placeholder = new Dictionary < string , string > ( ) ;
796
+ var index = 0 ;
797
+ foreach ( Match match in rgx . Matches ( template ) )
798
+ {
799
+ if ( index >= values . Length )
800
+ break ;
801
+ if ( ! placeholder . ContainsKey ( match . Value ) )
802
+ {
803
+ placeholder . Add ( match . Value , values [ index ++ ] ) ;
804
+ }
805
+ }
806
+
807
+ // replace them with the property value from setting
808
+ foreach ( var pro in placeholder )
809
+ template = template . ReplaceCaseInsensitive ( pro . Key , pro . Value ) ;
810
+
811
+ return template . Replace ( " " , " " ) ;
779
812
}
780
813
781
814
/// <summary>
0 commit comments