Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
i am trying to split a string until a specific pattern for e.g

below is my string

e.g. 123456 AL0120102090990AL01303030CS01999998888777

i want the above to be split into two

123456 AL0120102090990AL01303030
123456 CS01999998888777

pls help me !

[Edit - just posting the code from OP comment below (and bumping by default - sorry)]
managed to read the string from "123456 AL0120102090990AL01303030" i dont know how to continue further to read the rest , this is the code i am using
                    dim str, lngDelimiter , strFull  as string 
                    str = "AL0120102090990AL01303030CS01999998888777"
                    lngDelimiter = InStr(1, strFull, "CS01")
                    If lngDelimiter > 0 Then
                        'parse out everythig before the delimiter
                        strSubString = Strings.Left(str, lngDelimiter - 1)
the above will return this
AL0120102090990AL01303030


how to read the rest of the string value?
Posted
Updated 21-Feb-13 12:43pm
v2
Comments
Chris Reynolds (UK) 21-Feb-13 12:13pm    
With only one sample string it is difficult to give an answer. Post any ideas you've tried already and more of your sample data so that we can help
Sergey Alexandrovich Kryukov 21-Feb-13 12:16pm    
No, you need to define formally what should be done. An example is not a definition.
—SA
keerthi23 21-Feb-13 13:20pm    
i managed to read the string from "123456 AL0120102090990AL01303030" i dont know how to continue further to read the rest , this is the code i am using
dim str, lngDelimiter , strFull as string
str = "AL0120102090990AL01303030CS01999998888777"
lngDelimiter = InStr(1, strFull, "CS01")
If lngDelimiter > 0 Then
'parse out everythig before the delimiter
strSubString = Strings.Left(str, lngDelimiter - 1)
the above will return this
AL0120102090990AL01303030

how to read the rest of the string value?
Sergey Alexandrovich Kryukov 21-Feb-13 14:16pm    
How can this possibly be a problem? you have original string and first part of it, so... Just look at System.String class help...
—SA
joshrduncan2012 21-Feb-13 14:48pm    
My +5.

1 solution

Please use this example to learn from. Please lookup each statement that you do not fully understand in the Help file.

VB
Option Strict On
Option Explicit On

...


Dim intDelimiter As Integer
Dim strFull As String
Dim strSubString1 As String
Dim strSubString2 As String
strFull = "AL0120102090990AL01303030CS01999998888777"
intDelimiter = strFull.IndexOf("CS01") ' Find delimiter
If intDelimiter > 0 Then
    strSubString1 = strFull.Substring(0, intDelimiter) ' First part of string
    strSubString2 = strFull.Substring(intDelimiter)    ' Second part of string
    MsgBox(strSubstring1 & vbNewLine & vbNewLine & strSubstring2)
End If


Note: Tested using Visual Basic 2012 (.NET Framework 4.0)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900