By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

Finding out substring

P: 1
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.
Feb 11 '13 #1
Share this Question
Share on Google+
1 Reply


IronRazer
P: 83
Hello Savita Yadav,
If your string is "Sun Mon Tue" and you want to find "Mon" then try this :
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim Str1 As String = "Sun Mon Tue"
  3.         Dim Str2 As String = ""
  4.         If Str1.Contains("Mon") Then
  5.             Str2 = Str1.Substring(Str1.IndexOf("Mon"), 3)
  6.         End If
  7.     End Sub
  8.  
If your string contains "Mon" more than once and you want to find the last one in the string then use this :
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim Str1 As String = "Sun Mon Tue Wed Mon Fri"
  3.         Dim Str2 As String = ""
  4.         If Str1.Contains("Mon") Then
  5.             Str2 = Str1.Substring(Str1.LastIndexOf("Mon"), 3)
  6.         End If
  7.     End Sub
  8.  
Feb 11 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.