String To Array

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Comatose Comatose is offline Offline Feb 22nd, 2006, 7:45 am |
-1
Another Small And Simple Function To Take Each Character of a string, and put it into an Array, This helps significantly when you need to sift through a string. This Function Uses The spush (String Push) Function, Also In Code Snippits.
Quick reply to this message  
Visual Basic 4 / 5 / 6 Syntax
  1. Public Function str2Array(xString As String) As String()
  2. Dim tmpArray() As String
  3. Dim tmpchar As String
  4.  
  5. ' /* For Each Character In The String */
  6. For I = 1 To Len(xString)
  7.  
  8. ' /* Retrieve The Character */
  9. tmpchar = Mid(xString, I, 1)
  10. ' /* Push It Into The Temporary Array */
  11. spush tmpArray, tmpchar
  12. Next I
  13.  
  14. ' /* Return The Array To The Calling Procedure */
  15. str2Array = tmpArray
  16. End Function
0
wilsonjan wilsonjan is offline Offline | Oct 18th, 2006
Couldn't you just do:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. xString.ToCharArray

The only difference would be that you'd have a char array instead of a string array.

Alternatively, a better way in .net 2.0 would be to use the Array.ConvertAll method.

Regards,

Jan.
 
0
wilsonjan wilsonjan is offline Offline | Oct 18th, 2006
Apologies, I was being a bit dim and thought this group included .net

:cry:
 
 

Message:


Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC