Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: ocean10000

Message Too Old, No Replies

separating text - looking for function

     

buck1107

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

10+ Year Member



Hi,
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:
Impnum_I1._a.


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!

marcel

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?

buck1107

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 ]

buck1107

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.

marcel

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
Response.Write(s)
Next

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

' Iterate by using splitCount
For i As Integer = 0 To splitCount - 1
Response.Write(splitString(i))
Next

' 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