字符串数组? [英] An Array of Strings?
问题描述
大家好,
我需要在一个字符串中获取一个值(通过富文本框),我已经设法使用字符串的split属性将文本拆分为多个子字符串.
我需要将它们放置在数组中,以允许它们分别读取并添加到其他字符串中.我有以下
Hi All,
I need to take a value in a string (from a rich text box) I have managed to split up the text into substrings with the the split property of strings.
I need to place these in an array to allow them to read seperatly and added to other strings and on. I have the following
foreach (string subString in ValueCommand2.Split(''\n''))
{
Command2[g] = subString;
g++;
// MessageBox.Show(Command2);
}
那是正确分割字符串的正确方法吗?
现在的问题是将Command2声明为字符串数组
我有
That is the correct wat of splitting up the string right?
The problem is now declairing Command2 as an array of strings
I have
string Command2[] = new string array[5];
这不对吗?
Glenn
This is wrong isn''t it?
Glenn
推荐答案
拆分 [ ^ ]已经为您提供了一个字符串数组,因此您所需要做的就是:
Split[^] already gives you an array of Strings, so all you have to do is this:
String ValueCommand2 = "/* some lines of text belong in here */";
String[] Command2 = ValueCommand2.Split(new char[] { '\n' });
您可以使用Array
的Length属性来获取数组的大小.
问候,
You can get the size of the array by using the Array
''s Length property.
Regards,
我使用"List< string> stringlist = new List< string>()",这使我可以使用stringlist.Add("string添加");您可以使用stringlist.sort().并且创建时不必声明特定的大小...
stringlist = ValueCommand2.Split(''\ n'').ToList()//bam
I use "List<string> stringlist = new List<string>()" This enables me to use stringlist.Add("string to add"); and you can use stringlist.sort(). and you don''t have to declare a specific size when you create it...
stringlist = ValueCommand2.Split(''\n'').ToList() //bam
解决了!
string Command2[] = new string[5];
string[] Command2 = new string[5];
给自我的注意事项在寻求帮助之前,请先看一下代码!
Note to Self Look at your code before you shout for help!
这篇关于字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!