Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET arrays
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 18-Jan-13 19:02pm
Comments
Sergey Alexandrovich Kryukov at 19-Jan-13 0:03am
   
For goodness sake, why?! And how can it possibly be a problem? What did you try?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
sathish2k10 at 29-Jan-13 22:34pm
   
Thanks....
Sergey Alexandrovich Kryukov at 29-Jan-13 23:32pm
   
You are very welcome.
Good luck, call again.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

    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:
Dim strArray() as string = ToStrArray("sample")
  Permalink  
Comments
sathish2k10 at 29-Jan-13 22:34pm
   
Thanks.....!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<pre lang="vb">
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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());
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 DamithSL 165
4 Sergey Alexandrovich Kryukov 155
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 15 Oct 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100