Click here to Skip to main content
15,887,416 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I have
C#
Textbox1.text= "Kumar, Ravi (Customer - Back office) - C088888"


I want to fetch "C088888" from above string wherein it is followed by last " - " string.Please let me know how can i get this ?


Thanks & Regards
Care Career
Posted
Updated 6-Aug-12 19:07pm
v2

1 solution

Hi,

try this code. I tested it on your string and got your desired result:
VB
Private Sub Form1_Load(sender As Object, e As EventArgs)
    Textbox1.Text = "Kumar, Ravi (Customer - Back office) - C088888"
    Dim res As String() = Textbox1.Text.Split("-"C)
    If res.Length >= 2 Then
        Dim number As String = res(res.Length - 1).Replace(" ", "")
        MessageBox.Show(number)
    End If
End Sub
 
Share this answer
 

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