如何在C#中定义定界符 [英] how to define a delimiter in C#

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

问题描述

我遇到了问题

我有一个文本文件,使用空格将其填充到列中

我想知道如何在
中定义定界符

hi people i have a problem

i have a text file that is padded into columns using white spaces

i want to know how can i define the delimiter in the

DataSet ds = TextToDataSet.Convert("c:\test.txt", "MyNewTable", "????????");



以便分隔符将列之间的所有空白用作分隔符

现在的问题是空格不是全部都是相同的空格

文件中的每一行都有不同数量的空格

有人可以帮我吗

这 ?????? i1m寻找\ t不起作用的原因是"\ s *"不起作用试图创建正则表达式,但也不起作用吗?

我需要一个定界符来忽略数据之间的所有空白

并且每行中空格的数量不一样,每行之间有5个数据,第2行有10或20个数据,所以现在我需要知道如何定义该定界符,以便它使用任何数量



so that the delimiter takes all the white spaces between the columns as a delimiter

the problem now is the white spaces isn''t all the same amount of spaces

every row in the file has different amount of spaces

can anyone assist me please

the ?????? is what i1m looking for the \t doesn''t work the "\s*" doesn''t work tried to create a regex but doesn''t work either?

i need a delimiter to ignore all the white spaces between data

and the amount of white spaces aren''t the same in each row row one has like lets say 5 and row 2 has like 10 or 20 between the data so now i need to know how to define that delimiter so that it uses any amount of white spaces as the delimiter?

推荐答案

如果您引用的是
If you are referring to this article, I suggest you ask the author in the forum at the bottom of article.


您可以在对数据进行任何操作之前尝试执行以下操作:

You could try something like this before doing anything with the data:

string myString = "a    b      c";
do
{
   myString = myString.Replace("  ", " ");
}
while (myString.IndexOf("  " >= 0);
myString = myString.Trim();


这篇关于如何在C#中定义定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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