The attached code works, apart from the area between the 2 sets of "---------------" lines; specifically I think lines labelled 10 and 20.
The highlighted area of code splits the text using " " as delimiter, then splits any remaining hyphenated words by "-" as delimiter, but retains the hyphen, on one or other of the resulting 'words'.
The problem is that although it displays the correct words in InkEditBox 2, it overwrites the value of articleSpltArr(j) with the value of hyphenWordArr(1), and loses the original string value at that value of j. Not what I had in mind.
I had thought that redimming the array as I have done would preserve the original value, add another string to the array, and make that one = hyphenWordArr(1). But this isnt what's happening.
hyphenWord and hyphenWordArr only exist to help performing the split; they aren't needed for anything else.
Short of putting hyphenWordArr(1) and articleSpltArr(j)'s values into a third array, what can I do to make this work properly?
Re: 3 levels of 'split' string; 1 level not working
I'm not a VB6 guy but when I read what it is that you're trying to do, my first thought is to just use RegEx. If I have this correctly: you're wanting to get all words separated by whitespace and by hyphens, discard the whitespace but preserve the hyphen. If so then you can use the following pattern on a RegEx split:
Code:
(-)|\s
The grouping of the hyphen will preserve the character in the split while leaving the whitespace ungrouped discards it. So if you were to have the following text:
Code:
this is some words and this-word was hypenated just like this-one too
Then it would be split like this:
Code:
this
is
some
words
and
this
-
word
was
hypenated
just
like
this
-
one
too
Now I've read that VB6 doesn't come with native RegEx support but you are able to use Microsoft's VBScript RegEx library(look here). Also for what it's worth, here is an example in .NET:
Code:
Dim text As String = Console.ReadLine() 'Get some text
Dim words() As String = Regex.Split(text, "(-)|\s") 'Split the text by the hyphen and whitespace while preserving the hyphen
Console.WriteLine(String.Join(Environment.NewLine, words)) 'Print out the split up text
Re: 3 levels of 'split' string; 1 level not working
That looks like a very useful level of control to have. Maybe I should upgrade to .NET; I only use VB6 because its what I've had on the pc for a few years now.
Re: 3 levels of 'split' string; 1 level not working
I'm not going to tell you whether you should move to .NET or not because from what I understand there is a learning curve. But you are able to use RegEx within VB6 using the VBScript library, I would first explore trying that and if you get stumped then come back here with what you're having trouble with.
Re: 3 levels of 'split' string; 1 level not working
Originally Posted by moorea21
That looks like a very useful level of control to have.
A VB6-version could look like:
Code:
Private Sub Form_Load()
EnumWordsOn "...foo, bar...? foo-bar, foo- bar, foo -bar."
End Sub
Sub EnumWordsOn(S, Optional Match)
With CreateObject("VBScript.RegExp")
.Global = 1: .Pattern = "\w+|-"
For Each Match In .Execute(S): Debug.Print Match: Next
End With
End Sub