How to invoke multiple function from string "Mystring.ToUpper().FirstPart(3).Replace("M","Ok") C# .net

问题描述 投票:0回答:1

在服务器端想要对字符串进行嵌套操作。 .它将采用动态格式。我正在为此尝试使用剃刀引擎。有任何想法吗.. 例如:“Mystring.ToUpper().FirstPart(3).Replace("M","Ok")" 这个字符串用函数名提到。

Var input =  "Mystring.ToUpper().FirstPart(3).Replace("M","Ok");
FirstPart(int val){
.
.
return result;
}

output : OkYS

"Mystring.ToUpper().FirstPart(3).Replace("M","Ok")

Mystring.ToUpper() = MYSTRING,

MYSTRING.FirstPart(3) = MYS,

MYS.Replace("M","Ok")= OkYS

注意:输入将是dynamic.

"Mystring.ToUpper().FirstPart(3).Replace("M","Ok")"

(或)

"Mystring.ToUpper().Replace("M","Ok")"

(或)

“Mystring.ToLower().FirstPart(3)..

或任何..

c# asp.net backend razorengine
1个回答
0
投票
public static class StringHelper
{
    public static string Formatter(this string value,bool toUpper, string original ,string toReplace,int startIndex , int endIndex)
    {
       return value.ToUpper().Replace(original ,toReplace).Substring(startIndex,endIndex);     
    }
    public static string Formatter(this string value,bool toUpper, string original ,string toReplace)
    {
       return value.ToUpper().Replace(original ,toReplace);     
    }
    public static string Formatter(this string value,bool toUpper,int startIndex , int endIndex)
    {
       return value.ToUpper().Substring(startIndex,endIndex);     
    }
    public static string Formatter(this string value,int startIndex , int endIndex)
    {
       return value.Substring(startIndex,endIndex);     
    }
    public static string Formatter(this string value, string original ,string toReplace)
    {
       return value.Replace(original ,toReplace);     
    }
}

    Console.WriteLine("test".Formatter(true,"T","TS",0,3)); 
    Console.WriteLine("test".Formatter(true,"T","TS"));
    Console.WriteLine("test".Formatter(true,"T","TS"));
    Console.WriteLine("test".Formatter(0,4));
    Console.WriteLine("test".Formatter("T","TS"));
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.