如何过滤字符串中的指定值 [英] How to Filter specif value in a string

查看:65
本文介绍了如何过滤字符串中的指定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string sInput =";
sInput =

string sInput ="";
sInput =

MLOOPO BW 21      1     2       15     15      0    0      0     30    0 <br />
MLOOPI IC 23     0     0 *      0      0                              ''''    ''''   30    0 



我需要使用拆分获取每行的值以获取每列的确切值

问题是当该值为null或我需要标识的空格以便保存到分配为null或空白的列中时.这是因为第7列的值为空,所以第10列的值转到了第7列.

我下面的代码获得价值



I need to get the value per row using the split to get the exact value per column

The problem is when the value is null or space I need to Identify in order for me to save in a column assigned as null or blank. What is happening is the value for column 10 goes to column 7 becuase the value of column 7 is null.

my code below to get value

string[,] ADPH = new string[13,13];
int iData_x = 0;

string[] sValue = sInput.Split('' '');
int y = 0;

foreach (string sword in sValue)
{
 if (!string.IsNullOrEmpty(sword))
    {
     ADPH[iData_x, y] = sword;
     y = y + 1;
    }
}

推荐答案

为什么不将字符串转换为字节数组并以这种方式对其进行迭代?你想做什么 ?您知道数组是13 x 13,所以不要相信数据会告诉您何时步进值(尽管iData_x在此代码中从未更改),而只是使用您的已知值对其进行迭代.
Why don''t you turn the string into a byte array and iterate over it that way ? What are you trying to do ? You know the array is 13 x 13, so don''t trust the data to tell you when to step over the values ( although iData_x never changes in this code ), just iterate over it using your known values.


您能给我一个有关如何使用Iterate的示例,因为我还没有尝试过.感谢您的快速答复
Can you give me an example on how to use Iterate since I haven''t tried it. Thanks for your quick reply


如果您编辑帖子而不是发布假的答案",那真的会是另一个问题,这会更容易.假设您拥有13x13的数据数组,而不仅仅是发布的内容:

for(int x = 0; x< 13; ++ x)
for(int y = 0; y< 13; ++ y)
{

ADPH [x,y] = sValue [x +(y * 13)];

}

从我头顶上掉下来.假设您的字符串数组正确.就像我说的那样,我个人会使用字节数组来做到这一点.
It would be easier if you edited your post instead of posting a bogus ''answer'' that''s really another question. Assuming you HAVE a 13x13 array of data, and not just what you posted:

for (int x = 0; x < 13; ++x)
for (int y = 0; y < 13; ++y)
{

ADPH[x,y] = sValue[x+(y*13)];

}

Off the top of my head. Assuming your string array is correct. Like I said, I''d do that with a byte array, personally.


这篇关于如何过滤字符串中的指定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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