将值分配给锯齿数组(字符串) [英] Assigning values to a Jagged Array (String)

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

问题描述

如何将一组用户给定的字符串输入分配给锯齿状数组?

输入句子的数量可能因用户而异.

例子:-孩子吃了米饭.我们去旅行了. < =输入是给用户的输入(通过文本框).必须将每个句子的每一行和单词分配给每一列.

数组的行和列值
行:-
array [0] [] =孩子吃了米饭. < =第一行
array [1] [] =我们进行了一次旅行< =第二行

列:-
array [0] [0] => child
array [0] [1] =>吃

******************************************
如何访问每行的最后一个索引?

谢谢.

How can you assign set of user given string inputs to a jagged array?

Number of input sentences may differ from user to user.

Example :- child ate rice. We went on a trip. <= Input is a user given one (through a text box). Each sentence must be allocated each row and words to columns.

row and Column values of the array
Row:-
array[0] [] = child ate rice. <= first row
array[1] [] = We went on a trip <= second row

Column:-
array[0] [0] =>child
array[0] [1] => ate

*************************************
How can I access the last index of each row?

Thank you.

推荐答案

您的问题被简化为以下内容:如何在每个维度(在您的情况下为两个)中获取数组的长度. >
如果行和列的编号是从零开始的(这是默认值),请使用方法System.Array.GetLength(int dimension),请参见 http://msdn.microsoft.com/en-us/library/system.array. getlowerbound.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.array. getupperbound.aspx [ ^ ].

—SA
You problem is reduced to the following one: how to get length of array in each of its (two in your case) dimensions.

If your rows and columns numbers are zero-based (which is the default), use the method System.Array.GetLength(int dimension), see http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx[^].

You can also find your bound of indexing for non zero-based arrays. For this purpose, use the methods System.Array.GetLowBound(int dimension) and System.Array.GetUpperBound(int dimension). See:
http://msdn.microsoft.com/en-us/library/system.array.getlowerbound.aspx[^],
http://msdn.microsoft.com/en-us/library/system.array.getupperbound.aspx[^].

—SA


我想此链接将帮助您http://msdn.microsoft.com/zh-cn/library/2s05feca.aspx
I suppose this link will help you http://msdn.microsoft.com/en-us/library/2s05feca.aspx


这篇关于将值分配给锯齿数组(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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