我给2个变量的数据类型为字符串和整数。

但是C#表示它们不存在。

已尝试将某些对象作为TexttoSplit对象{私人套装; },但仍无法正常运行。

任何帮助将非常感激!

private static List<string> SplitTextByLengthEngine(string Texttosplit, int MaxLineLength)
{

    List<string> RetVal = new List<string>();
    MaxLineLength = Math.Min(MaxLineLength, TexttoSplit.Length);

    int LastIndex = TexttoSplit.Substring(0, Math.Min((MaxLineLength + 1), TextToSplit.Length)).LastIndexOf(" ");
    if (((TextToSplit.Length <= MaxLineLength)
    || (LastIndex == -1)))
    {
        RetVal.Add(TexttoSplit.Substring(0, MaxLineLength));
        string RemainingText = TexttoSplit.SubString(MaxLineLength, (TextToSplit.Length - MaxLineLength)).Trim();
    }
    if ((RemainingText.Length > 0))
    {
        RetVal.AddRange(SplitTextByLengthEngine(RemainingText, MaxLineLength));
    }
    else
    {
        // Track backwards to find previous non-space character
        int Index = (LastIndex - 1);
        while (((Index >= 0)
        && (TextToSplit.SubString(Index, 1) == " ")))
        {
            Index--;
        }

        if ((Index >= 0))
        {
            RetVal.Add(TextToSplit.SubString(0, (Index + 1)));
            string RemainingText = TexttoSplit.SubString((Index + 1), (TextToSplit.Length
            - (Index + 1))).Trim();
        }
        if ((RemainingText.Length > 0))
        {
            RetVal.AddRange(SplitTextByLengthEngine(RemainingText, MaxLineLength));

        }
        return RetVal;
    }

}

最佳答案

方法参数称为Texttosplit

在方法主体中,您引用TextToSplit

注意大写/小写的区别

09-06 05:29