Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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]


VB
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]Code block fixed - OriginalGriff[/edit]
Posted
Updated 5-Feb-12 22:35pm
v2
Comments
CPallini 6-Feb-12 5:06am    
Why don't you work directly with Chars?

1 solution

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
 
Share this answer
 
Comments
Espen Harlinn 6-Feb-12 6:24am    
Good reply, my 5 :)
Sergey Alexandrovich Kryukov 6-Feb-12 9:51am    
Thank you, Espen.
--SA
zoyakhan 19-Feb-12 11:16am    
thanks.
for each was good idea. solved using that.
sorry for replying late.
thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900