Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
Hai all,
I am developing one VB Application in VS2010. In that i am using Mid() for getting the string, but here we need to give an start position(Integer) and length of string(integer).
But i need to get the string between two characters .... Is it possible?
How.....?
For Example:
String= "CHimaN"
I want the string in Between Chars C and N
How i get Hima As my string....

Please give me a solution.......
Waiting for ur response................
Posted
Updated 3-Jan-12 20:32pm
v2
Comments
Sergey Alexandrovich Kryukov 4-Jan-12 1:11am    
...and, more exactly, what do you need to do?
--SA
Himachandra 4-Jan-12 1:14am    
I need to get the string between two chars..... Just like
String--- CHimaM
i need the String Between Chars C & M ie., Hima
How can i get that in VB
Reiss 4-Jan-12 3:17am    
Do you need to account for multiple instances of either C or M, e.g. CdddMCssMMC
Himachandra 4-Jan-12 4:10am    
No

1 solution

Try:
VB
Dim source As String = "CHimaM"
Dim extract As String = ""
Dim start As Integer = source.IndexOf("C"C) + 1
Dim [end] As Integer = source.IndexOf("M"C)
If start >= 0 AndAlso [end] > start Then
    extract = source.Substring(start, [end] - start)
End If
 
Share this answer
 
Comments
Himachandra 5-Jan-12 23:38pm    
Yah Itz working.....
Thank You Mr OriginalGriff
OriginalGriff 6-Jan-12 3:28am    
You're welcome!

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