"字符串"在当前上下文中不存在

Mat*_*ari 0 c#-4.0

我将以下函数从vb.net转换为c#,但我无法弄清楚这一点.

错误4当前上下文中不存在名称"字符串"

public string GetBetween(string StringText)
    {
        string functionReturnValue = null;

        string TMP = null;
        string FromS = null;
        string ToS = null;
        FromS = "<Modulus>";
        ToS = "</Modulus>";

        TMP = Strings.Mid(StringText, Strings.InStr(StringText, FromS) + Strings.Len(FromS), Strings.Len(StringText));
        TMP = Strings.Left(TMP, Strings.InStr(TMP, ToS) - 1);

        functionReturnValue = TMP;

        return functionReturnValue;

    }
Run Code Online (Sandbox Code Playgroud)

Jef*_*ado 5

Strings是一个VB.net类.如果您希望能够使用它,则必须引用Microsoft.VisualBasic.dll程序集并使用Microsoft.VisualBasic命名空间.

如果你尽可能避免使用VB.net方法会更好.

public string GetBetween(string str, string start = "<Modulus>", string end = "</Modulus>")
{
    var startIndex = str.IndexOf(start);
    var endIndex = str.LastIndexOf(end);
    if (startIndex == -1 || endIndex == -1 || startIndex > endIndex)
        return str;
    return str.Substring(startIndex + start.Length,
                         str.Length - start.Length - end.Length);
}
Run Code Online (Sandbox Code Playgroud)