请帮忙.不知道从哪里开始! [英] please help. not sure where to start!

查看:74
本文介绍了请帮忙.不知道从哪里开始!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

对于许多编码人员来说,这似乎微不足道,但是老实说,我不知道从哪里开始,所以有人可以建议我吗?谢谢...

我正在使用Visual Studio 2008,C#.net,Windows窗体...

我想在Windows窗体上有一个编辑/文本框,该框将接受如下所示的数字字符串:

Hello.

This may seem trivial to many coders, but i honestly do not know where to start, so could someone please advise me? Thank you...

I am using Visual Studio 2008, C# .net, windows forms...

I want to have an edit/text box on my windows form that will accepts a string of digits like the following:

456345-007876-343234-765676-543456-566565-321234-345654


然后在去除-"间隔符之后,我想将上面的内容表示为字节数组,这将是x字节编码,例如:


Then after stripping out the ''-'' spacers, i want to represent the above as a byte array, which would be an x byte encoding, something like:

{0x56,0x33,0x56,0x66,0x77........} (example)


然后将字节数组BACK转换为数字字符串,例如:


Then convert the byte array BACK to a string of digits, e.g.:

456544-676777-231234-567423-456776-567898-998788-455654


我发现了许多示例,这些示例允许我将代码编码/解码为十六进制或以64为基数或以32为基数,但是重要的是我可以用数字表示数据.

希望有人能帮助我吗?
提前非常感谢您
Steve


I have found many examples that allow me to encode/decode to hex or base 64 or base 32 etc, but it is important that i can represent my data with numbers.

Hope some on can please help me?
Thank you VERY much in advance
Steve

推荐答案

stephen.darling写道:
stephen.darling wrote:

但重要的是我可以用数字表示我的数据.

but it is important that i can represent my data with numbers.



我不确定你的意思是什么.您希望十六进制值不包含A-F吗?字节数组是做什么用的?您能否将数字直接存储为字节,例如0x45、0x63等?



I''m not sure what you mean by this. You want for the hex values to not contain A-F ? What is the byte array for ? Could you just store the numbers directly into the bytes, as 0x45, 0x63, etc ?


取决于您要精确地存储什么;

这将使用ASCII码作为数字"
Depends on what exactly you are after;

This will use the ASCII code for the "number"
byte[] arrayValue = System.Text.Encoding.UTF8.GetBytes(string);





将实际数字存储在字节中[]



or

Store the actual number in a byte[]

byte[] arrayValue = new byte[string.Length]

//walk the string and get each individual number then store in the byte[]

arrayValue[index] = Convert.ToInt16(string);


按照aspdotnetdev的建议工作,我认为您要执行的操作是将字符串转换为数字,然后稍后再返回,但是对字节的想法有所了解.请改用int.
原文:
Working on what aspdotnetdev suggests below, I think what you are trying to do is convert the string into numbers and back again later, but have got stuck on the idea of bytes. Use int instead.
Original:
string rawData = "456345-007876-343234-765676-543456-566565-321234-345654"

转换为字符串数组:

Convert to an array of strings:

string[] separated = rawData.Split(''-'');

创建一个足以容纳它们的整数数组:

Create an array of ints big enough to hold them:

int[] numeric = new int[separated.Length];

填充数组:

Fill the array:

int i = 0;
foreach (string s in separated)
    {
    if (!int.TryParse(s, out numeric[i]))
        {
        throw new ApplicationException("Invalid characters in expression");
        }
    i++;
    }


向后转换只是相反:


Converting back is just the reverse:

StringBuilder sb = new StringBuilder();
string sep = "";
foreach (int no in numeric)
    {
    sb.Append(sep + no.ToString("D6"));
    sep = "-";
    }
string converted = sb.ToString();


这篇关于请帮忙.不知道从哪里开始!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆