Click here to Skip to main content
14,299,846 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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

Solution 2

If your string is fixed format, then String.Substring[^] is the easy way:
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:

'  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()
   

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




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