Click here to Skip to main content
12,954,403 members (58,654 online)
Rate this:
 
Please Sign up or sign in to vote.
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 18-Jan-13 18:02pm
Comments
   
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 29-Jan-13 22:34pm
   
Thanks....
Sergey Alexandrovich Kryukov 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,143
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 15 Oct 2013
Copyright © CodeProject, 1999-2017
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