Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This my String 'C21F-6573-34E0-C3F0-PNBM-QUR7-4VXT-TAXC-U0/H-XW=='
0123456789012345678901234567890123456789012345678
<----1---><----2---><----3---><----4---><----5-->
Total no character is 49 of above string.
I want to pick up the substring from left side 'P' char to end point, i.e. starting index position is 19.
But i want to searching '-'(dash sign) in the above string.

How will i solve above problem???
Please help me.....
Posted

 
Share this answer
 
If your string is fixed format, then String.Substring[^] is the easy way:
VB
Dim part As String = full.Substring(20)

If you really need to work with a variable position, based on the data after the fourth hyphen, then use a Regex:

VB
'  Imports System.Text.RegularExpressions

'  Regular expression built for Visual Basic on: Wed, Dec 21, 2011, 07:58:27 AM
'  Using Expresso Version: 3.0.3634, http://www.ultrapico.com
'  
'  A description of the regular expression:
'  
'  Match a prefix but exclude it from the capture. [\w+-\w+-\w+-\w+-]
'      \w+-\w+-\w+-\w+-
'          Alphanumeric, one or more repetitions
'          -
'          Alphanumeric, one or more repetitions
'          -
'          Alphanumeric, one or more repetitions
'          -
'          Alphanumeric, one or more repetitions
'          -
'  [1]: A numbered capture group. [.*]
'      Any character, any number of repetitions
'  
'

Public Dim regex As Regex = New Regex( _
      "(?<=\w+-\w+-\w+-\w+-)(.*)", _
    RegexOptions.IgnoreCase _
    Or RegexOptions.Multiline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    )


' This is the replacement string
Public Dim regexReplace As String = _
      "$& [${Day}-${Month}-${Year}]"


'' Replace the matched text in the InputText using the replacement pattern
' Dim result As String = regex.Replace(InputText,regexReplace)

'' Split the InputText wherever the regex matches
' Dim results As String() = regex.Split(InputText)

'' Capture the first Match, if any, in the InputText
' Dim m As Match= regex.Match(InputText)

'' Capture all Matches in the InputText
' Dim ms As MatchCollection = regex.Matches(InputText)

'' Test to see if there is a match in the InputText
' Dim IsMatch As Boolean = regex.IsMatch(InputText)

'' Get the names of all the named and numbered capture groups
' Dim GroupNames As String() = regex.GetGroupNames()

'' Get the numbers of all the named and numbered capture groups
' Dim GroupNumbers As Integer() = regex.GetGroupNumbers()
 
Share this answer
 

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