Search code examples
c#substringindexoflastindexof

Substring and IndexOf and LastIndexOf in c#


I have this string :

464-138234-AVENANCE

And I need this output on three items :

 464
 138234
 AVENANCE

For first item I have try with success :

strMyString.SelectedItem.Value.Substring(0, strMyString.SelectedItem.Value.IndexOf('-'))

Output : 464

I can't to extract the two and three items :

strMyString.SelectedItem.Value.Substring(1, strMyString.SelectedItem.Value.IndexOf('-'))

The output is :

64-

Can you help me?

Thank you in advance for any help, really appreciated.


Solution

  • Try this

      string myStr="464-138234-AVENANCE";
        string[] data= myStr.Split('-');