| separating text - looking for function
|
buck1107

msg:4202330 | 6:30 pm on Sep 15, 2010 (gmt 0) | 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: 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

msg:4202343 | 6:51 pm on Sep 15, 2010 (gmt 0) | The split function would be your best option here, why would you want to use something else?
|
buck1107

msg:4202365 | 7:20 pm on Sep 15, 2010 (gmt 0) | 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

msg:4202389 | 7:47 pm on Sep 15, 2010 (gmt 0) | 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

msg:4202601 | 7:18 am on Sep 16, 2010 (gmt 0) | 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) |
|
|
|
|