我在arraylist处理中面临问题. [英] i am facing problem in arraylist handling .

查看:76
本文介绍了我在arraylist处理中面临问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串mstr.我将其unicode值存储在名为(arr)的数组列表中. 我想检查数组列表中的下一个元素是否是某个已定义类别的unicode.(0942,0943)etc那么应该不插入零,但是如果
找不到类别,我想在数组中插入零,但无法正确地循环.
例如:
输入arraylist为(arr)= [0915,092C,0942,0924,0930];输出数组列表为= [0915; 0000,092C,0942,0924; 0000,0930; 0000]


i have a string mstr. i store its unicode values in an arraylist called (arr).
i want to check if the next element in the array list is a unicode of some defined category.(0942,0943)etc then there should be no insertion of zero, but if
the category is not found i want to insert a zero in the array but am not able to iterate the loop correctly.
example:
input arraylist as (arr) =[0915, 092C,0942, 0924,0930] ; output arraylist as =[0915;0000, 092C,0942, 0924;0000,0930;0000]


For Each myCh As Char In mStr
                 he = Hex((System.Convert.ToInt32(myCh)))
                 arr.Add(he)
                 CharPos.X += 15
             Next
             Dim k As Integer = arr.Count
             For i1 = 0 To k

                 If arr(i1) = "93E" Or arr(i1) = "93F" Or arr(i1) = "940" Or arr(i1) = "941" Or arr(i1) = "942" Or arr(i1) = "947" Or arr(i1) = "948" Or arr(i1) = "94B" Or arr(i1) = "94C" Or arr(i1) = "902" Or arr(i1) = "903" Or arr(i1) = 0 Then
                     arr(i1) = arr(i1)

                 Else
                     arr.Insert(i1 + 1, 0)
                     k = k + 1
                 End If
                 i1 = i1 + 1

             Next



[edit]已修复代码块-OriginalGriff [/edit]



[edit]Code block fixed - OriginalGriff[/edit]

推荐答案

到目前为止,我看到了三个问题:

您可以迭代0 to k,但不能,因为元素#k不存在.您尝试在只有k个元素时重复循环k+1次. 1)请勿使用此类应变量名称; 2)计数0 to k-1; 3)完全不做;使用foreach.

不要使用ArrayList;在.NET Framework v.2.0中引入泛型已使其过时.对于新开发,请使用System.Collections.Generic.List和其他通用集合.非泛型类是不好的;您将需要类型转换,这是一件坏事.请参阅:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.collections. generic.aspx [ ^ ].

最后,我看不到您在哪里遍历每个字符串的字符.

—SA
I see three problems so far:

You iterate 0 to k but you cannot, because the element #k does not exist. You are trying to repeat the loop k+1 times while you have only k elements. 1) Don''t use such should variable names; 2) count 0 to k-1; 3) don''t do it at all; use foreach.

Don''t use ArrayList; it is rendered obsolete by introduction of generics in .NET Framework v. 2.0. For new development, use System.Collections.Generic.List and other generic collections. Non-generic classes are bad; you will need a type cast, which is a bad thing. Please see:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[^],
http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx[^].

Finally, I don''t see where do you iterate through character of each string.

—SA


这篇关于我在arraylist处理中面临问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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