Solved

Help split string in a text array

Posted on 2013-12-19
6
332 Views
Last Modified: 2013-12-19
Hi experts

I have an array a(i).

The array contains text like

1. The Beach
2. The Song
3. The Sun
The Sun

How do I split the existing array into two parts:
(1) is the text up to the full stop eg 1.
(2) is the balance of the text eg The Beach
If there is no fullstop "." (1) would be empty (2) would be the whole lot of the text.

Then I've got to populate my table. I can move through the table okay, I just not sure how to work with the splitting the text - it does my head in!

        For k = 1 To i - 1
            selection.range.text = (1)
            selection.moveright wdcell, 1
            selection.range.text = (2)
        Next

Can someone please help me get (1) and (2) from my array a(i) please.
0
Comment
Question by:Fi69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39728906
If there is no fullstop "." (1) would be empty (2) would be the whole lot of the text.

There seems to be a flaw in the logic. How could one know where the old record ends and the new one begins without the period?
0
 

Author Comment

by:Fi69
ID: 39728927
What if I try a different approach.

The text is coming from headings, they could be numbered on non numbered.

How do I grab the text from the right of the full stop?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39728973
How are  you putting the headings into the array?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:Fi69
ID: 39729077
Yes. I've generated it from a Table of contents - level 1 only. Converted that TOC to plain text, then added each paragraph in as my array.
0
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 total points
ID: 39729093
Try this/get what I am trying to do. If you have questions, please reply

Sub sample()

    Dim a() As String, i As Long
    Dim wdcell As Long
    wdcell = 1
    a = Split("1.The Beach,2.The Song,3.The Sun,The Sun", ",")
    
    For i = 0 To UBound(a)
        If Len(a(i)) > 0 Then
            If InStr(a(i), ".") > 0 Then
                Selection.Value = Left(a(i), InStr(a(i), "."))
                Cells(ActiveCell.Row + wdcell, ActiveCell.Column + wdcell).Select
                Selection.Value = Mid(a(i), InStr(a(i), ".") + 1, Len(a(i)))
            Else
                Selection.Value = vbNullString
                Cells(ActiveCell.Row + wdcell, ActiveCell.Column + wdcell).Select
                Selection.Value = a(i)
            End If
            
        End If
        Cells(ActiveCell.Row + wdcell, ActiveCell.Column + wdcell).Select
    Next i
End Sub

Open in new window

0
 

Author Comment

by:Fi69
ID: 39729142
That's perfect. Thank you so much!!!!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 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