【问题标题】:How to make into fives-block my byte numbers from the textbox?如何将文本框中的字节数变成五个块?
【发布时间】:2016-04-18 21:25:27
【问题描述】:

首先,抱歉我的英语不好解释我的问题。

这似乎是一个简单的问题,但我无法完成这项工作。例如,当我输入几个数字时,我想将它们分成五个块。之后,我想对每五个数字进行一次数学运算。

1111011058108161105811110 ...必须拆分,

比如,

*11110 x 5 =... in block array...
11058 x 5 =... in another block array.*

【问题讨论】:

  • 到目前为止你尝试过什么代码?
  • 是的,我在 for 循环中尝试过子字符串命令。但我还没有得到结果。
  • 你为什么不编辑你的问题,然后发布你到目前为止所做的工作。除非您提供起点,否则我们无法帮助您调试

标签: c# arrays split byte


【解决方案1】:

试试这个

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> output = new List<int>();
            string input = "1111011058108161105811110";
            for(int i = 0; i < input.Length; i += 5)
            {
                output.Add(int.Parse(input.Substring(i,5)));
            }
        }
    }
}

【讨论】:

    【解决方案2】:

    你可以试试这样的。

    int numDigits = 5;
    
    
    string str = "111101105810816110581111023";
    
    str = str + new string(' ', numDigits - str.Length % numDigits);
    
    for(int i = 0; i < str.Length; i = i + 5)
    {
        int number = Convert.ToInt32(str.Substring(i, numDigits));
        Console.WriteLine("{0} * 5 = {1}", number, number * 5);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-01
      • 2014-02-06
      • 1970-01-01
      • 2019-06-02
      相关资源
      最近更新 更多