Finding out substring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Savita Yadav
    New Member
    • Feb 2013
    • 1

    Finding out substring

    Sir, Mu question is finding substring in the main string but each time my string changing such as
    first it may be "Sun Mon Tue"
    second time it may be "Sun Tue Fri Sat"
    or it may any any days or all days in a week.
  • IronRazer
    New Member
    • Jan 2013
    • 83

    #2
    Hello Savita Yadav,
    If your string is "Sun Mon Tue" and you want to find "Mon" then try this :
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Str1 As String = "Sun Mon Tue"
            Dim Str2 As String = ""
            If Str1.Contains("Mon") Then
                Str2 = Str1.Substring(Str1.IndexOf("Mon"), 3)
            End If
        End Sub
    If your string contains "Mon" more than once and you want to find the last one in the string then use this :
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Str1 As String = "Sun Mon Tue Wed Mon Fri"
            Dim Str2 As String = ""
            If Str1.Contains("Mon") Then
                Str2 = Str1.Substring(Str1.LastIndexOf("Mon"), 3)
            End If
        End Sub

    Comment

    Working...