Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

separating text - looking for function



6:30 pm on Sep 15, 2010 (gmt 0)

10+ Year Member

I'm trying to separate text with a vb function, but I'm not really sure what to use.
Here's an example of the format of the text:

The length of the substrings between the underscores can be of varying length.
I would like to have the text up to the first underscore as the first substring, the next as the 2nd, the next as the 3rd.
Aside from the split function, are there other options?

Many thanks!


6:51 pm on Sep 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

The split function would be your best option here, why would you want to use something else?


7:20 pm on Sep 15, 2010 (gmt 0)

10+ Year Member

Thanks - I was reading that it was only released with VB 6, so not with older versions. Is that correct?

Here's the link
[vbexplorer.com ]


7:47 pm on Sep 15, 2010 (gmt 0)

10+ Year Member

Perhaps more specifically what I need is some way to assign the different substrings to variables. I see on the SPLIT function that you can set the delimiter, count, and compare, but getting each distinct substring is a mystery.


7:18 am on Sep 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Here is some example code.

' The string to split
Dim myString As String = "Impnum_I1._a."

' Split the string
Dim splitString As String() = myString.Split("_")

' Iterate through the string collection
For Each s As String In splitString

' Get number (count) of seperate strings
Dim splitCount As Integer = splitString.Length

' Iterate by using splitCount
For i As Integer = 0 To splitCount - 1

' Or get the strings one by one manually
Dim firstString As String = splitString(0)
Dim secondString As String = splitString(1)
Dim thirdString As String = splitString(2)

Featured Threads

Hot Threads This Week

Hot Threads This Month