Substring and IndexOf and LastIndexOf in c#

6.7k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

Try this

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

why not?

string msg = "464-138234-AVENANCE";
var myArray = msg.Split('-');