字符串数组还是问题数组? [英] Array of strings or array of problems?
问题描述
我在文本框中读取了大量数据,然后需要拆分
如果我使用foreach语句分隔字符(例如#0D)
然后,我需要将它们拆分为字符串数组,这将使生活变得困难
如果我使用以下内容(分度号为#0D)
I have a large ammount of data read in a text box that I then need to split up
if I use a foreach statement to seperate on a character (#0D for instance)
I then need to split them in to array of strings will this be making life difficult
if I use the below (with delimeters as #0D)
string Data;
//string[Number_Records] = Data_Values[Number_Records];
int a =0;
Data = rtbReturnedData.Text;
// MessageBox.Show(Data);
foreach (string subString in Data.Split(delimeters))
{
// Data_Values[a] = subString;
MessageBox.Show(subString);
}
问题是subString包含了单独的值,现在我理想情况下需要一个字符串数组,我可以通过a整数将subString复制到一个增量中.
在此之前分配Number_Records,以允许上传可变长度的文件,我是否声明字符串数组正确?我的意图是将值读回十六进制,我以为字符串是保存它们的最佳方法,但是我可以找到的所有字符串数组示例都使用
The problem is subString then contains the seperate values, now I ideally need an array of strings that I can copy subString into an increase via the a integer.
The Number_Records is assigned before this point to allow for upload variable length files am i declaring the string array right? my intention as the values read back as hex, my thinking was a string is the best method of holding them, but all the examples I can find of string arrays use
string[Number_Records] = Data_Values[Number_Records];
但我似乎无法使其正常工作.
Glenn
but I can''t seem to get it to work.
Glenn
推荐答案
您的问题可以通过简单的修改来解决.
Your issue can be solved much simpler with a small modification.
string Data;
int a=0;
string[] stringParts = Data.Split(delimeters);
现在,您有了零件的字符串数组.如果查看string.Split,您将看到返回值已经是您想要的字符串数组.
Now you have a string array of the parts. If you look at string.Split, you will see that the return value is already the string array which is what you want.
这篇关于字符串数组还是问题数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!