字符串数组? [英] An Array of Strings?

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

问题描述

大家好,

我需要在一个字符串中获取一个值(通过富文本框),我已经设法使用字符串的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属性来获取数组的大小.

问候,

-MRB



You can get the size of the array by using the Array''s Length property.

Regards,

—MRB


我使用"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屋!

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