944,094 Members | Top Members by Rank

Ad:
-2

String To Array

by on Feb 22nd, 2006
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.
Visual Basic 4 / 5 / 6 Code Snippet (Toggle Plain Text)
  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
Comments on this Code Snippet
Oct 18th, 2006
0

Re: String To Array

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.
Unverified User
wilsonjan is offline Offline
3 posts
since Oct 2006
Oct 18th, 2006
0

Re: String To Array

Apologies, I was being a bit dim and thought this group included .net

:cry:
Unverified User
wilsonjan is offline Offline
3 posts
since Oct 2006
Mar 5th, 2010
0

Re: String To Array

spush <---What's this? i tried the code in vb6 but it won't work. It says "not defined"
Newbie Poster
jfc2k4 is offline Offline
1 posts
since Mar 2010
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB variables/values to access97 DB
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: User Functions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC