I am retrieving data from a DB table using SqlDataReader
in ASP.net. I append the retrieved data in a string builder and after that, dump the contents of the string builder into a text file. My problem is that in that text file white spaces are showing up between one column and another ... How can I remove the excess white spaces from my text file?
我正在使用ASP.net中的SqlDataReader从DB表中检索数据。我将检索到的数据附加到字符串构建器中,然后将字符串构建器的内容转储到文本文件中。我的问题是,在文本文件中,一列和另一列之间出现了空格……如何从文本文件中删除多余的空格?
Thanks in advance.
提前谢谢。
2 个解决方案
#1
5
1. Text.Trim();
2. Text.Replace(" ", string.empty);
#2
0
private string process(string s)
{
int len = s.Length;
int current=0;
StringBuilder sb = new StringBuilder(len);
while (current < len-1)
{
if (!(s[current] == ' ' && s[current + 1] == ' ') &&
!(s[current] == '\n' && s[current + 1] == '\n')
)
{
sb.Append(s[current]);
}
current++;
}
return sb.ToString();
}
#1
5
1. Text.Trim();
2. Text.Replace(" ", string.empty);
#2
0
private string process(string s)
{
int len = s.Length;
int current=0;
StringBuilder sb = new StringBuilder(len);
while (current < len-1)
{
if (!(s[current] == ' ' && s[current + 1] == ' ') &&
!(s[current] == '\n' && s[current + 1] == '\n')
)
{
sb.Append(s[current]);
}
current++;
}
return sb.ToString();
}