Click here to Skip to main content
12,394,883 members (79,207 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# VB VB.NET
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 21-Feb-13 6:06am
Updated 21-Feb-13 12:43pm
CHill60157.3K
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.
Sergey Alexandrovich Kryukov 21-Feb-13 14:54pm
   
:-)
keerthi23 10-Jan-14 12:32pm
   
Just wanna let you know , the reason i came here with the problem is i don't know , it may be easy for you but for me i am just the learner
Sergey Alexandrovich Kryukov 10-Jan-14 17:32pm
   
No problem with that, but I gave you an advice above, did you try to use it? If you did, what else was the problem?
—SA
keerthi23 24-Apr-14 16:38pm
   
Thanks for the help , i was able to finish it with your help... Really thanks very much
Sergey Alexandrovich Kryukov 24-Apr-14 16:41pm
   
Great. Keep up.
—SA

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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)
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100