DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

How to store each individuals characters into a variable?

By: rekha singh | 27 Mar 2010 1:03 pm

Hi,

I have to know how to split the characters from a string and store it in a separate variable?. The string used is "hello" . I want to store the characters h,e,l,l,o into a single array. For Example, the string "hello" is given through the textbox. I need to store it in a array named "a". (i.e) a[0]=h
a[1]=e
a[2]=l
a[3]=l
a[4]=o...If anyone knows please reply me.......   

Comments

 using an array list:

        Dim helloString As String = "hello"
        Dim holder As New ArrayList
        Dim x As New Char

        For Each x In helloString
            holder.Add(x)
        Next

By: rekha singh | 27 Mar 2010

I would probably start by taking the length of the input and using a for-next loop, something like:
z = len(input_string)
for x = 0 to z-1
a(x) = mid(input_string, x+1, 1)
next

Mind you, I'm just starting out in VBScript and there may be a better way to do this, but I think that might work.

By: rekha singh | 27 Mar 2010

How about this:

Dim testString1 As String = "ABC"
'Create an array containing "A", "B", and "C".
Dim charArray() As Char = testString1. ToCharArray
 

By: rekha singh | 27 Mar 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move