使用split方法重用字符串数组 [英] Re-use a string array using the split method

查看:66
本文介绍了使用split方法重用字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字符串列表,我想取每个字符串,并使用split方法填充字符串数组,用它做一些东西,并且该过程在for中。环。在每次通过for之后我希望重用相同的字符串数组。而且,正如你所知道的c#中所有人都知道的那样,阵列就会不断增加。我怎么说每次从头开始?我知道这将变得非常容易,一旦指出我,我会感到非常愚蠢,但请指出给我!!!!

解决方案

检查一下。可能重复的问题:
http:// bytes .com / topic / c-sharp / answe ... e-bounds-array


用于字符串拆分方法示例:
http://www.dotnetperls.com/string-split


< blockquote>感谢Adriancs,但没有回答我的问题。它使用了dotnetperls,这让我有了使用split方法的想法。假设我使用StreamReader将数据串读入内存:

a1 a2 a3

b1 b2 b3

c1 c2 c3等

展开 | 选择 | Wrap | 行号


Hello Joe,

我不确定这是否有效.. 。

将字符串数组声明为

string [] data = null;
在for循环之外的
或尝试添加

data = null;

就在for循环的右大括号之前......


I have a list of input strings and I want to take each string and using the split method populate a string array, do some stuff with it and that process is in a "for" loop. After each pass through the "for" loop I want to re-use the same string array. And, as all you fundi''s in c# will know, the array just keeps getting added to. How do I say start from scratch each time? I know this is going to be real easy, and I''m going to feel real foolish once it is pointed out to me, but please point it out to me!!!!

解决方案

check this out. Possible duplicate question:
http://bytes.com/topic/c-sharp/answe...e-bounds-array

for string split method examples:
http://www.dotnetperls.com/string-split


Thanks Adriancs, but doesn''t answer my question. It was using dotnetperls that gave me the idea to use the split method. Say that I read, using StreamReader, strings of data into memory:
a1 a2 a3
b1 b2 b3
c1 c2 c3 etc.

Expand|Select|Wrap|Line Numbers


Hello Joe ,
I am not sure if this works...
Declare the string array as
string[] data = null;
outside the for loop or try adding
data = null;
just before the closing brace of for loop.....


这篇关于使用split方法重用字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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