[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

split

Posted on 2000-03-15
13
Medium Priority
?
190 Views
Last Modified: 2010-05-02
How can I split a word up into seperate individual characters?

Key words here are "word" and "characters". Clinton would be:
c
l
i
n
t
o
n
0
Comment
Question by:pmaxon
  • 5
  • 5
  • 3
13 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2620902
try ssomething like this
Private Sub Form_Load()
  Dim TestString
  Dim A() As String
  Dim I As Integer

  TestString = "William Jefferson Clinton"
  A = Split(TestString)

  For I = LBound(A) To UBound(A)
    MsgBox A(I)
  Next
  End
End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2621012
Ruchi:
"Try something like this".. <---- That's a definitive answer?.. Shame on you for locking this question down!!!
Now, lets just suppose the questioner does not have VB6.. and ergo NO split command.. what then? Don't me get wrong.. your answer is deserved and accurate in every way.. I just think it belongs as a comment.. and its merit left to the judgement of the questioner.. <smile>.
----------------------
A solution both VB5 / VB6 compatable.

<----- Code Begin ----->

Dim strInput as String
strInput = "This is a test"

Dim strChars() as String
Redim strChars(Len(strInput))

Dim lngIndex as Long
For lngIndex = 1 to Len(strInput)
   strChars(lngIndex - 1) = Mid$(strInput, lngIndex, 1)
Next lngIndex

<----- Code End ----->

Tada..

0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2621032
OK OK OK. Thanks, WSH2



If you have VB6 then you can use Split function

Private Sub Form_Load()
     Dim strString As String
    Dim arrWords As Variant
    Dim i As Integer

    strString = "FirstName MName LastName"
    arrWords = Split(strString, " ")
    For i = 0 To UBound(arrWords)
        MsgBox arrWords(i)
    Next

End Sub




If you have VB5 and earlier versions:


Private Sub Form_Load()
   Dim strString As String
    Dim arrWords() As String
    Dim i As Integer
     
    strString = "FirstName MName LastName"
    Do Until strString = "" 
        ReDim Preserve arrWords(i)
        If InStr(strString, " ") > 0 Then
            arrWords(i) = Trim(Left(strString, InStr(strString, " ") - 1))
            strString = Mid(strString, InStr(strString, " ") + 1)
        Else
            arrWords(i) = Trim(strString)
            strString = "" 
        End If
        i = i + 1
    Loop
     
    For i = 0 To UBound(arrWords)
        MsgBox arrWords(i)
    Next
     
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:wsh2
ID: 2621157
Ruchi:
<tipping hat and bowing>.. and Thank YOU as well.. <smile>.

--------------------------------------
pmaxon writes: "How can I split a word up into seperate individual characters?"

Ruchi, questioner is asking how to parse the LETTERS in a word.. not the words themselves.. <smile>.

And a suggestion that I hope you may find useful.. with string variables and string functions such as Instr and Mid it is much more efficient to use the Instr$ and Mid$ forms of the functions (assuming you are NOT using Katanese or some other highly extended characterset.. which fortunately, most of us do not). WITHOUT the $ sign suffix, VB uses two bytes per character, WITH the $ suffix, VB only uses one.. which, as indicated earlier, is absolutely fine on almost all Western (civilization) style computers.. <smile>

Anyhow.. once again, Thank YOU very much for your comments.. I for one, am most appreciative of your thoughts.. keep them coming.. <smile>
0
 

Author Comment

by:pmaxon
ID: 2621163
Edited text of question.
0
 

Author Comment

by:pmaxon
ID: 2621200
Edited text of question.
0
 

Author Comment

by:pmaxon
ID: 2621210
Edited text of question.
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 300 total points
ID: 2621228
I have tested it!

Private Sub Form_Load()
  Dim TestString
  Dim b As String
  Dim I As Integer

  TestString = "William Jefferson Clinton"

  For I = 1 To Len(TestString)
  b = Mid$(TestString, I, 1)
    MsgBox b
  Next I
  End
End Sub
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2621237
You can use debug.print instead of MsgBox. You will see
c
l
i
n
t
o
n
in the immediate window.
0
 

Author Comment

by:pmaxon
ID: 2621242
Adjusted points from 50 to 75
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2621262
Thank you very much, Pmaxon, for the points! I am glad that I could be of any help to you! Again, thanks.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2621309
PSsssst.... a TIP.. test for Zero length strings before running, k?.. <smile> and a <wink>.

0
 

Author Comment

by:pmaxon
ID: 2621866
Very good idea wsh2... And thank YOU Ruchi for the help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month18 days, 4 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question