Before you can write general code to extract a substring from a string, you have to know what the rules are. I could provide you with ten different code snippets that would do exactly as you asked but they would not work with any other data. You need to explain to us exactly what those rules are. For instance, are you saying that you want the text from a specific character index to another? The text between the first and second slash? The text between the first and last slash? Something else? Computers can't read your mind so you have to give them EXACT instructions. We can't read your mind either.
Dim MyStr As String = cmbPurBill.Text
Dim fstring As String
Dim MYBILL As String
For x = 7 To Len(MyStr) - 3
fstring = Mid(MyStr, x, 1)
If Mid(MyStr, x, 1) = "/" Then Exit For
MYBILL = MYBILL + fstring
Next x
TxtBillNo.Text = MYBILL
Dim firstSlashIndex = myString.IndexOf("/") Dim substringStartIndex = firstSlashIndex + 1 Dim secondSlashIndex = myString.IndexOf("/", substringStartIndex) Dim substringLength = secondSlashIndex - substringStartIndex Dim mySubstring = myString.Substring(substringStartIndex, substringLength)
I have a string like
dim mystr as String= 'A-001/123a/20'
I want to pick "123a" only from mystr using VB.NET
how can I ?
Thanks in advance.
Dim mystr As String = "A-001/123a/20"
Dim s() As String = mystr.Split("/"c)
Dim reqString As String = s(1)
Hi
Here is one of many possibilities.
VB.NET:Dim mystr As String = "A-001/123a/20" Dim s() As String = mystr.Split("/"c) Dim reqString As String = s(1)