Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
How to add a string value into array variable using VB.Net?

Ex:

dim txt as string
dim strArray() as string
txt=sample

in array i want to put that text "sample" in following way.

strArray(0)=s
strArray(2)=a
strArray(3)=m
strArray(4)=p
strArray(5)=l
strArray(6)=e
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jan-13 0:03am    
For goodness sake, why?! And how can it possibly be a problem? What did you try?
—SA

 
Share this answer
 
Comments
sathish2k10 29-Jan-13 22:34pm    
Thanks....
Sergey Alexandrovich Kryukov 29-Jan-13 23:32pm    
You are very welcome.
Good luck, call again.
—SA
VB
Public Shared Function ToStrArray(ByVal value As String) As String()
    Dim result As String() = New String(value.Length - 1) {}
    For i As Integer = 0 To value.Length - 1
        result(i) = New String(value(i), 1)
    Next
    Return result
End Function

Example:
VB
Dim strArray() as string = ToStrArray("sample")
 
Share this answer
 
Comments
sathish2k10 29-Jan-13 22:34pm    
Thanks.....!
VB
<pre lang="vb">
 
Share this answer
 
here is another solution
string txt = null;
string[] strArray = new string [6];
txt = "sample";

for (int i = 0; i <txt.length;> {
strArray[i] = txt.ToString().Substring(i,1);
}
//after storing you will get result as it is
//like
for (int i = 0; i < strArray.Length; i++)
{
Console.WriteLine(strArray[i].ToString());
}
 
Share this answer
 

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