首页 > 解决方案 > 当前上下文中不存在 TextToSplit

问题描述

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

但是 C# 说它们不存在。

已经尝试过对象 TexttoSplit { get; 私人套装;} 但仍然不能正确运行。

任何帮助将非常感激!

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;
    }

}

标签: c#

解决方案


方法参数被调用Texttosplit

在您引用的方法主体中TextToSplit

注意大写/小写的区别


推荐阅读