1

我在 IBM 仿真器环境中工作。我正在尝试获取一行文本并按空格分隔以返回该行中的每个单词。但是,当打印到控制台时,它只显示第一个字母。此代码过去在用于原始文本或 api 结果时有效。但是,在 IBM Emulator 上实现相同的代码时不会。

例如,如果模拟器中的行是HEALTHSELECT OF TEXAS,下面的代码将正确打印第一个和第二个控制台。使用双 for 循环仅打印第一个字母。实际列出的控制台输出如下:

looking for healthselect of texas          in away from home care

healthselect
of
texas

looking for h in a 
looking for h in w
looking for h in a
looking for h in y
looking for e in a 
looking for e in w
looking for e in a
looking for e in y
looking for a in a 
looking for a in w
looking for a in a
looking for a in y

C#代码:

public bool inStringAll(string needle, string haystack)
{
    needle = Regex.Replace(needle.ToLower(), @"\r\n", string.Empty);
    haystack = Regex.Replace(haystack.ToLower(), @"\r\n", string.Empty);

    Console.WriteLine($"looking for {needle} in {haystack");

    string[] needleArr = needle.Split(' ');
    string[] haystackArr = haystack.Split(' ');

    for(int j = 0; j < needleArr.Length; j++)
        Console.WriteLine(needleArr[j]);

    int percent = 0;
    int increment;
    bool decision = false;

    if (needleArr.Length > 3)
         increment = 100 / 3;
    else increment = 100 / needleArr.Length;

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < haystackArr.Length; j++)
        {
            Console.WriteLine("looking for " + needle[i] + " in " + haystack[j]);
            if (needleArr[i] == haystackArr[j])
            {
                percent += increment;
            }
        }
    }
    Console.WriteLine($"Percent: {percent}%");

    if (percent >= 50)
        decision = true;

    return decision;
}

有没有人使用过这种模拟器并且在正确获取这些值时遇到任何问题?我使用 EXTRA 处理过旧的 attachmate 系统!基本并且没有问题,但这是我第一个使用 C#.net 的 IBM 系统客户,因此可能会有所不同。

4

0 回答 0