asp.net 如何从字符串“Mystring.ToUpper().FirstPart(3).Replace(“M”,“Ok”)“中调用多个函数C# .net

0md85ypi  于 2023-03-20  发布在  .NET
关注(0)|答案(1)|浏览(91)

在服务器端要做一个字符串嵌套操作。它将在动态格式。我正在尝试与剃刀引擎为这一点。任何想法..“Mystring.ToUpper().FirstPart(3).Replace(“M”,“Ok”)”这个字符串与函数名一起提到。

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

output : OkYS

“我的字符串.ToUpper().第一部分(3).替换(“M”,“确定”)
Mystring.到上一个()= Mystring,
神秘字符串。第一部分(3)=马来西亚,
最小值替换(“最小值”,“确定”)=确定

注意:输入将是动态的

“我的字符串.ToUpper().第一部分(3).替换(“M”,“确定”)”
(或)
Mystring.ToUpper().替换(“M”,“确定”)
(或)
“我的字符串.到下().第一部分(3)..
或任何..

7kjnsjlb

7kjnsjlb1#

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"));

相关问题