Solved

Help split string in a text array

Posted on 2013-12-19
6
324 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
  • 3
  • 2
6 Comments
 
LVL 26

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 26

Expert Comment

by:MacroShadow
ID: 39728973
How are  you putting the headings into the array?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now