How to find Substring from a string

Posted by Pcjoshi under ASP.NET on 9/19/2012 | Points: 10 | Views : 7081 | Status : [Member] | Replies : 3
hi,
i have a string i want to find substring ?




Responses

Posted by: T.Saravanan on: 9/19/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try the below..


string Input = "This is a Sample Text";
string output = Input.Substring(9,5); // Directly assign Start Index and Length
output = Input.Substring(Input.IndexOf("Sample"), (Input.LastIndexOf("Sample")-1)); // Using IndexOf and LastIndexOf for getting exact value
output = Input.Contains("Sample") ? "True" : "False"; // If the value is exist return True or False using "Contains" operator




Thanks,
T.Saravanan

Pcjoshi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Perumal93 on: 9/19/2012 [Member] Starter | Points: 25

Up
0
Down
Private Function SubString(ByVal InputString As String) As String

Dim input As String = InputString

Dim temp As String

temp = input.Substring(0, 3)

Return temp

End Function

=========================================================================================================================================

Input : Substring

Output : Sub

Pcjoshi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/20/2012 [Member] Starter | Points: 25

Up
0
Down
thanq Perumal&Saravanan

Thanks & Regards
Hari

Pcjoshi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response